diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 9880de9..031cbbd 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -120,7 +120,7 @@ final class ApiController extends Controller private function validateBillCreate(RequestAbstract $request) : array { $val = []; - if (($val['client/customer'] = empty($request->getData('client') && empty($request->getData('supplier')))) + if (($val['client/customer'] = (empty($request->getData('client')) && empty($request->getData('supplier')))) ) { return $val; } @@ -274,10 +274,12 @@ final class ApiController extends Controller $status = !\is_dir($pdfDir) ? \mkdir($pdfDir, 0755, true) : true; if ($status === false) { + // @codeCoverageIgnoreStart $response->set($request->uri->__toString(), new FormValidation(['status' => $status])); $response->header->status = RequestStatusCode::R_400; return; + // @codeCoverageIgnoreEnd } $view = new View($this->app->l11nManager, $request, $response); diff --git a/Models/Bill.php b/Models/Bill.php index 6e74dab..ba46a0f 100755 --- a/Models/Bill.php +++ b/Models/Bill.php @@ -621,11 +621,35 @@ class Bill implements \JsonSerializable return new NullMedia(); } + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'number' => $this->number, + 'type' => $this->type, + 'shipTo' => $this->shipTo, + 'shipFAO' => $this->shipFAO, + 'shipAddress' => $this->shipAddress, + 'shipCity' => $this->shipCity, + 'shipZip' => $this->shipZip, + 'shipCountry' => $this->shipCountry, + 'billTo' => $this->billTo, + 'billFAO' => $this->billFAO, + 'billAddress' => $this->billAddress, + 'billCity' => $this->billCity, + 'billZip' => $this->billZip, + 'billCountry' => $this->billCountry, + ]; + } + /** * {@inheritdoc} */ public function jsonSerialize() { - return []; + return $this->toArray(); } } diff --git a/Models/BillElement.php b/Models/BillElement.php index ac17f62..0a8bf81 100755 --- a/Models/BillElement.php +++ b/Models/BillElement.php @@ -133,11 +133,28 @@ class BillElement implements \JsonSerializable $this->item = $item; } + /** + * {@inheritdoc} + */ + public function toArray() : array + { + return [ + 'id' => $this->id, + 'order' => $this->order, + 'item' => $this->item, + 'itemNumber' => $this->itemNumber, + 'itemName' => $this->itemName, + 'itemDescription' => $this->itemDescription, + 'quantity' => $this->quantity, + 'bill' => $this->bill, + ]; + } + /** * {@inheritdoc} */ public function jsonSerialize() { - return []; + return $this->toArray(); } } diff --git a/Models/BillType.php b/Models/BillType.php index c69ab39..f9cc24e 100755 --- a/Models/BillType.php +++ b/Models/BillType.php @@ -48,7 +48,7 @@ class BillType /** * Constructor. * - * @param string $name Name/identifier of the attribute type + * @param string $name Name * * @since 1.0.0 */ diff --git a/Models/SalesBillMapper.php b/Models/SalesBillMapper.php index 8f34bbf..a8c7b9e 100755 --- a/Models/SalesBillMapper.php +++ b/Models/SalesBillMapper.php @@ -232,7 +232,7 @@ final class SalesBillMapper extends BillMapper /** * Placeholder */ - public static function getItemTopCustomers(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array + public static function getItemTopClients(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array { $depth = 3; diff --git a/info.json b/info.json index 02dd43f..93e0551 100755 --- a/info.json +++ b/info.json @@ -31,8 +31,9 @@ "load": [ { "pid": [ - "/sales/billing", - "/purchase/billing" + "/sales/bill", + "/purchase/bill", + "/warehouse/bill" ], "type": 4, "for": 0, diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index 327a5a0..e1d97d3 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -21,7 +21,7 @@ final class AdminTest extends \PHPUnit\Framework\TestCase { protected const NAME = 'Billing'; - protected const URI_LOAD = 'http://127.0.0.1/en/backend/admin/audit'; + protected const URI_LOAD = 'http://127.0.0.1/en/backend/sales/bill'; use \Modules\tests\ModuleTestTrait; } diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index b341dfc..1181374 100644 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -96,7 +96,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase * @covers Modules\Billing\Controller\ApiController * @group module */ - public function testBillCreate() : void + public function testBillClientCreate() : void { $response = new HttpResponse(); $request = new HttpRequest(new HttpUri('')); @@ -164,6 +164,80 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase self::assertGreaterThan(0, $result === null ? -1 : $result['response']?->getId()); } + /** + * Tests bill, bill element and bill pdf archive create + * + * @covers Modules\Billing\Controller\ApiController + * @group module + */ + public function testBillSupplierCreate() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + + $request->setData('supplier', 1); + $request->setData('address', null); + $request->setData('type', 1); + $request->setData('status', null); // null = system settings, value = individual input + $request->setData('performancedate', DateTime::generateDateTime(new \DateTime('2015-01-01'), new \DateTime('now'))->format('Y-m-d H:i:s')); + $request->setData('sales_referral', null); // who these sales belong to + $request->setData('shipping_terms', 1); // e.g. incoterms + $request->setData('shipping_type', 1); + $request->setData('shipping_cost', null); + $request->setData('insurance_type', 1); + $request->setData('insurance_cost', null); // null = system settings, value = individual input + $request->setData('info', null); // null = system settings, value = individual input + $request->setData('currency', null); // null = system settings, value = individual input + $request->setData('payment', null); // null = system settings, value = individual input + $request->setData('payment_terms', null); // null = system settings, value = individual input + + $this->module->apiBillCreate($request, $response); + + $bId = $response->get('')['response']->getId(); + self::assertGreaterThan(0, $bId); + + for ($k = 0; $k < 10; ++$k) { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + + $iId = \mt_rand(0, 10); + + $request->setData('bill', $bId); + $request->setData('item', $iId === 0 ? null : $iId); + + if ($iId === 0) { + // @todo: add text + } + + $request->setData('quantity', \mt_rand(1, 11)); + $request->setData('tax', null); + $request->setData('text', $iId === 0 ? 'Some test text' : null); + + // discounts + if (\mt_rand(1, 100) < 31) { + $request->setData('discount_percentage', \mt_rand(5, 30)); + } + + $this->module->apiBillElementCreate($request, $response); + self::assertGreaterThan(0, $response->get('')['response']->getId()); + } + + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('bill', $bId); + + $this->module->apiBillPdfArchiveCreate($request, $response); + + $result = $response->get(''); + self::assertGreaterThan(0, $result === null ? -1 : $result['response']?->getId()); + } + /** * @covers Modules\Billing\Controller\ApiController * @group module @@ -174,8 +248,25 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $request = new HttpRequest(new HttpUri('')); $request->header->account = 1; + $request->setData('invalid', '1'); $this->module->apiBillCreate($request, $response); self::assertEquals(RequestStatusCode::R_400, $response->header->status); } + + /** + * @covers Modules\Billing\Controller\ApiController + * @group module + */ + public function testBillElementCreateInvalidData() : void + { + $response = new HttpResponse(); + $request = new HttpRequest(new HttpUri('')); + + $request->header->account = 1; + $request->setData('invalid', '1'); + + $this->module->apiBillElementCreate($request, $response); + self::assertEquals(RequestStatusCode::R_400, $response->header->status); + } } diff --git a/tests/Models/BillElementTest.php b/tests/Models/BillElementTest.php index 1b1dd9a..9520ccf 100644 --- a/tests/Models/BillElementTest.php +++ b/tests/Models/BillElementTest.php @@ -45,9 +45,42 @@ final class BillElementTest extends \PHPUnit\Framework\TestCase self::assertInstanceOf('\phpOMS\Localization\Money', $this->element->totalPurchasePriceNet); } + /** + * @covers Modules\Billing\Models\BillElement + * @group module + */ public function testItemInputOutput() : void { $this->element->setItem(123); self::assertEquals(123, $this->element->item); } + + /** + * @covers Modules\Billing\Models\BillElement + * @group module + */ + public function testSerialize() : void + { + $this->element->order = 2; + $this->element->item = 3; + $this->element->itemNumber = '123456'; + $this->element->itemName = 'Test'; + $this->element->itemDescription = 'Description'; + $this->element->quantity = 4; + $this->element->bill = 5; + + self::assertEquals( + [ + 'id' => 0, + 'order' => 2, + 'item' => 3, + 'itemNumber' => '123456', + 'itemName' => 'Test', + 'itemDescription' => 'Description', + 'quantity' => 4, + 'bill' => 5, + ], + $this->element->jsonSerialize() + ); + } } diff --git a/tests/Models/BillTest.php b/tests/Models/BillTest.php index f2d75f2..b1c1bbd 100644 --- a/tests/Models/BillTest.php +++ b/tests/Models/BillTest.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Billing\tests\Models; use Modules\Billing\Models\Bill; +use Modules\Billing\Models\BillElement; use Modules\Billing\Models\BillStatus; use Modules\Billing\Models\BillType; use phpOMS\Localization\ISO4217CharEnum; @@ -139,4 +140,57 @@ final class BillTest extends \PHPUnit\Framework\TestCase $this->bill->addTracking('TEST'); self::assertEquals(['TEST'], $this->bill->getTrackings()); } + + /** + * @covers Modules\Billing\Models\Bill + * @group module + */ + public function testElementInputOutput() : void + { + $this->bill->addElement(new BillElement()); + self::assertCount(1, $this->bill->getElements()); + } + + /** + * @covers Modules\Billing\Models\Bill + * @group module + */ + public function testSerialize() : void + { + $this->bill->number = '123456'; + $this->bill->type = 2; + $this->bill->shipTo = 'To'; + $this->bill->shipFAO = 'FAO'; + $this->bill->shipAddress = 'Address'; + $this->bill->shipCity = 'City'; + $this->bill->shipZip = 'Zip'; + $this->bill->shipCountry = 'Country'; + $this->bill->billTo = 'To'; + $this->bill->billFAO = 'FAO'; + $this->bill->billAddress = 'Address'; + $this->bill->billCity = 'City'; + $this->bill->billZip = 'Zip'; + $this->bill->billCountry = 'Country'; + + self::assertEquals( + [ + 'id' => 0, + 'number' => '123456', + 'type' => 2, + 'shipTo' => 'To', + 'shipFAO' => 'FAO', + 'shipAddress' => 'Address', + 'shipCity' => 'City', + 'shipZip' => 'Zip', + 'shipCountry' => 'Country', + 'billTo' => 'To', + 'billFAO' => 'FAO', + 'billAddress' => 'Address', + 'billCity' => 'City', + 'billZip' => 'Zip', + 'billCountry' => 'Country', + ], + $this->bill->jsonSerialize() + ); + } } diff --git a/tests/Models/NullBill.php b/tests/Models/NullBill.php deleted file mode 100644 index 6697334..0000000 --- a/tests/Models/NullBill.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullBillElement.php b/tests/Models/NullBillElement.php deleted file mode 100644 index ecf1267..0000000 --- a/tests/Models/NullBillElement.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullBillType.php b/tests/Models/NullBillType.php deleted file mode 100644 index cd30551..0000000 --- a/tests/Models/NullBillType.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/PurchaseBillMapperTest.php b/tests/Models/PurchaseBillMapperTest.php new file mode 100644 index 0000000..c55f219 --- /dev/null +++ b/tests/Models/PurchaseBillMapperTest.php @@ -0,0 +1,152 @@ +getInt()); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetPurchaseBySupplierIdInvalid() : void + { + self::assertEquals(0, PurchaseBillMapper::getPurchaseBySupplierId(99999, new \DateTime('now'), new \DateTime('now'))->getInt()); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetAvgPurchasePriceByItemIdInvalid() : void + { + self::assertEquals(0, PurchaseBillMapper::getAvgPurchasePriceByItemId(99999, new \DateTime('now'), new \DateTime('now'))->getInt()); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetLastOrderDateByItemIdInvalid() : void + { + self::assertEquals(null, PurchaseBillMapper::getLastOrderDateByItemId(99999)); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetLastOrderDateBySupplierIdInvalid() : void + { + self::assertEquals(null, PurchaseBillMapper::getLastOrderDateBySupplierId(99999)); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetNewestItemInvoicesInvalid() : void + { + self::assertEquals([], PurchaseBillMapper::getNewestItemInvoices(99999)); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetNewestSupplierInvoicesInvalid() : void + { + self::assertEquals([], PurchaseBillMapper::getNewestSupplierInvoices(99999)); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetItemTopSuppliersInvalid() : void + { + self::assertEquals([[], []], PurchaseBillMapper::getItemTopSuppliers(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetItemRegionPurchaseInvalid() : void + { + self::assertEquals([], PurchaseBillMapper::getItemRegionPurchase(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetItemCountryPurchaseInvalid() : void + { + self::assertEquals([], PurchaseBillMapper::getItemCountryPurchase(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetItemMonthlyPurchaseCostsInvalid() : void + { + self::assertEquals([], PurchaseBillMapper::getItemMonthlyPurchaseCosts(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\PurchaseBillMapper + * @group module + */ + public function testGetSupplierMonthlyPurchaseCostsInvalid() : void + { + self::assertEquals([], PurchaseBillMapper::getSupplierMonthlyPurchaseCosts(99999, new \DateTime('now'), new \DateTime('now'))); + } +} diff --git a/tests/Models/SalesBillMapperTest.php b/tests/Models/SalesBillMapperTest.php new file mode 100644 index 0000000..5eec0af --- /dev/null +++ b/tests/Models/SalesBillMapperTest.php @@ -0,0 +1,170 @@ +getInt()); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetSalesByClientIdInvalid() : void + { + self::assertEquals(0, SalesBillMapper::getSalesByClientId(99999, new \DateTime('now'), new \DateTime('now'))->getInt()); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetAvgSalesPriceByItemIdInvalid() : void + { + self::assertEquals(0, SalesBillMapper::getAvgSalesPriceByItemId(99999, new \DateTime('now'), new \DateTime('now'))->getInt()); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetLastOrderDateByItemIdInvalid() : void + { + self::assertEquals(null, SalesBillMapper::getLastOrderDateByItemId(99999)); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetLastOrderDateByClientIdInvalid() : void + { + self::assertEquals(null, SalesBillMapper::getLastOrderDateByClientId(99999)); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetNewestItemInvoicesInvalid() : void + { + self::assertEquals([], SalesBillMapper::getNewestItemInvoices(99999)); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetNewestClientInvoicesInvalid() : void + { + self::assertEquals([], SalesBillMapper::getNewestClientInvoices(99999)); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetItemTopClientsInvalid() : void + { + self::assertEquals([[], []], SalesBillMapper::getItemTopClients(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetItemBillsInvalid() : void + { + self::assertEquals([], SalesBillMapper::getItemBills(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetClientItem() : void + { + self::assertEquals([], SalesBillMapper::getClientItem(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetItemRegionSalesInvalid() : void + { + self::assertEquals([], SalesBillMapper::getItemRegionSales(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetItemCountrySalesInvalid() : void + { + self::assertEquals([], SalesBillMapper::getItemCountrySales(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetItemMonthlySalesCostsInvalid() : void + { + self::assertEquals([], SalesBillMapper::getItemMonthlySalesCosts(99999, new \DateTime('now'), new \DateTime('now'))); + } + + /** + * @covers Modules\Billing\Models\SalesBillMapper + * @group module + */ + public function testGetClientMonthlySalesCostsInvalid() : void + { + self::assertEquals([], SalesBillMapper::getClientMonthlySalesCosts(99999, new \DateTime('now'), new \DateTime('now'))); + } +} diff --git a/tests/Models/StockBillMapperTest.php b/tests/Models/StockBillMapperTest.php new file mode 100644 index 0000000..aacf9b4 --- /dev/null +++ b/tests/Models/StockBillMapperTest.php @@ -0,0 +1,44 @@ +