bug fixes / dbmapper fixes

This commit is contained in:
Dennis Eichhorn 2021-12-19 20:20:38 +01:00
parent 351eb653dc
commit 71107e6c7a
7 changed files with 62 additions and 52 deletions

View File

@ -2,11 +2,10 @@
use Mpdf\Mpdf;
/**
* @var \phpOMS\Views\View $this
* @var \Modules\Billing\Models\Bill
*/
$bill = $this->getData('bill');
/** @var \phpOMS\Views\View $this */
/** @var \Modules\Billing\Models\Bill $bill */
$bill = $this->getData('bill');
/**
* @var \Modules\Billing\Models\BillElement[] $elements
*/

View File

@ -110,9 +110,10 @@ final class ApiController extends Controller
/* @var \Modules\Account\Models\Account $account */
$bill = new Bill();
$bill->createdBy = new NullAccount($request->header->account);
$bill->number = '{y}-{id}'; // @todo: use admin defined format
$bill->numberFormat = '{y}-{id}'; // @todo: use admin defined format
$bill->billTo = $request->getData('billto')
?? ($account->profile->account->name1 . (!empty($account->profile->account->name2) ? ', ' . $account->profile->account->name2 : '')); // @todo: use defaultInvoiceAddress or mainAddress. also consider to use billto1, billto2, billto3 (for multiple lines e.g. name2, fao etc.)
$bill->billAddress = $request->getData('billaddress') ?? $account->mainAddress->address;
$bill->billZip = $request->getData('billtopostal') ?? $account->mainAddress->postal;
$bill->billCity = $request->getData('billtocity') ?? $account->mainAddress->city;
$bill->billCountry = $request->getData('billtocountry') ?? $account->mainAddress->getCountry();
@ -144,6 +145,19 @@ final class ApiController extends Controller
return [];
}
/**
* Api method to create a bill
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiMediaAddToBill(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
if (!empty($val = $this->validateMediaAddToBill($request))) {
@ -153,6 +167,7 @@ final class ApiController extends Controller
return;
}
$uploaded = [];
if (!empty($uploadedFiles = $request->getFiles() ?? [])) {
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
[],

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace Modules\Billing\Controller;
use Modules\Billing\Models\BillMapper;
use Modules\Billing\Models\BillTypeL11n;
use Modules\Billing\Models\PurchaseBillMapper;
use Modules\Billing\Models\SalesBillMapper;
use Modules\Billing\Models\StockBillMapper;
@ -57,17 +55,34 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/Billing/Theme/Backend/sales-bill-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005104001, $request, $response));
$mapperQuery = SalesBillMapper::getAll()
->with('type')
->with('type/l11n')
->with('client')
->sort('id', OrderType::DESC)
->limit(25);
if ($request->getData('ptype') === 'p') {
$view->setData('bills',
SalesBillMapper::getAll()->with('client')->where('id', (int) ($request->getData('id') ?? 0), '<')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
$mapperQuery
->where('id', (int) ($request->getData('id') ?? 0), '<')
->where('client', null, '!=')
->where('type/l11n/language', $response->getLanguage())
->execute()
);
} elseif ($request->getData('ptype') === 'n') {
$view->setData('bills',
SalesBillMapper::getAll()->with('client')->where('id', (int) ($request->getData('id') ?? 0), '>')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
$mapperQuery->where('id', (int) ($request->getData('id') ?? 0), '>')
->where('client', null, '!=')
->where('type/l11n/language', $response->getLanguage())
->execute()
);
} else {
$view->setData('bills',
SalesBillMapper::getAll()->with('client')->where('id', 0, '>')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
$mapperQuery->where('id', 0, '>')
->where('client', null, '!=')
->where('type/l11n/language', $response->getLanguage())
->execute()
);
}

View File

@ -23,7 +23,6 @@ use phpOMS\Localization\ISO4217CharEnum;
use phpOMS\Localization\Money;
use Modules\Editor\Models\EditorDoc;
use Modules\Media\Models\NullMedia;
use Mpdf\Tag\P;
/**
* Bill class.
@ -416,14 +415,14 @@ class Bill implements \JsonSerializable
*/
public function __construct()
{
$this->netProfit = new Money(0);
$this->grossProfit = new Money(0);
$this->netCosts = new Money(0);
$this->grossCosts = new Money(0);
$this->netSales = new Money(0);
$this->grossSales = new Money(0);
$this->netDiscount = new Money(0);
$this->grossDiscount = new Money(0);
$this->netProfit = new Money(0);
$this->grossProfit = new Money(0);
$this->netCosts = new Money(0);
$this->grossCosts = new Money(0);
$this->netSales = new Money(0);
$this->grossSales = new Money(0);
$this->netDiscount = new Money(0);
$this->grossDiscount = new Money(0);
$this->createdAt = new \DateTimeImmutable();
$this->performanceDate = new \DateTime();

View File

@ -116,29 +116,29 @@ class BillElement implements \JsonSerializable
*/
public function __construct()
{
$this->singleListPriceNet = new Money();
$this->singleListPriceNet = new Money();
$this->singleListPriceGross = new Money();
$this->totalListPriceNet = new Money();
$this->totalListPriceGross = new Money();
$this->totalListPriceNet = new Money();
$this->totalListPriceGross = new Money();
$this->singleSalesPriceNet = new Money();
$this->singleSalesPriceNet = new Money();
$this->singleSalesPriceGross = new Money();
$this->totalSalesPriceNet = new Money();
$this->totalSalesPriceGross = new Money();
$this->totalSalesPriceNet = new Money();
$this->totalSalesPriceGross = new Money();
$this->singlePurchasePriceNet = new Money();
$this->singlePurchasePriceNet = new Money();
$this->singlePurchasePriceGross = new Money();
$this->totalPurchasePriceNet = new Money();
$this->totalPurchasePriceGross = new Money();
$this->totalPurchasePriceNet = new Money();
$this->totalPurchasePriceGross = new Money();
$this->singleProfitNet = new Money();
$this->singleProfitNet = new Money();
$this->singleProfitGross = new Money();
$this->totalProfitNet = new Money();
$this->totalProfitGross = new Money();
$this->totalProfitNet = new Money();
$this->totalProfitGross = new Money();
}
/**

View File

@ -189,9 +189,6 @@ final class PurchaseBillMapper extends BillMapper
*/
public static function getNewestItemInvoices(int $id, int $limit = 10) : array
{
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query = self::getQuery();
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
@ -212,9 +209,6 @@ final class PurchaseBillMapper extends BillMapper
*/
public static function getNewestSupplierInvoices(int $id, int $limit = 10) : array
{
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query = self::getQuery();
$query->where(self::TABLE . '_d1.billing_bill_supplier', '=', $id)
->limit($limit);

View File

@ -51,7 +51,7 @@ final class SalesBillMapper extends BillMapper
return self::getAll()
->with('type')
->where('id', $pivot, '<')
->where('transferType', BillTransferType::SALES)
->where('type/transferType', BillTransferType::SALES)
->limit($limit)
->execute();
}
@ -70,7 +70,7 @@ final class SalesBillMapper extends BillMapper
return self::getAll()
->with('type')
->where('id', $pivot, '>')
->where('transferType', BillTransferType::SALES)
->where('type/transferType', BillTransferType::SALES)
->limit($limit)
->execute();
}
@ -189,9 +189,6 @@ final class SalesBillMapper extends BillMapper
*/
public static function getNewestItemInvoices(int $id, int $limit = 10) : array
{
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query = self::getQuery();
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
@ -212,9 +209,6 @@ final class SalesBillMapper extends BillMapper
*/
public static function getNewestClientInvoices(int $id, int $limit = 10) : array
{
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query = self::getQuery();
$query->where(self::TABLE . '_d1.billing_bill_client', '=', $id)
->limit($limit);
@ -258,9 +252,6 @@ final class SalesBillMapper extends BillMapper
*/
public static function getItemBills(int $id, \DateTime $start, \DateTime $end) : array
{
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query = self::getQuery();
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
@ -281,9 +272,6 @@ final class SalesBillMapper extends BillMapper
*/
public static function getClientItem(int $client, \DateTime $start, \DateTime $end) : array
{
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
$query = BillElementMapper::getQuery();
$query->leftJoin(self::TABLE, self::TABLE . '_d1')
->on(BillElementMapper::TABLE . '_d1.billing_bill_element_bill', '=', self::TABLE . '_d1.billing_bill_id')