mirror of
https://github.com/Karaka-Management/oms-Billing.git
synced 2026-02-16 08:18:41 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
70f2c0887b
commit
351eb653dc
|
|
@ -16,6 +16,7 @@ namespace Modules\Billing\Admin\Install;
|
||||||
|
|
||||||
use Model\Setting;
|
use Model\Setting;
|
||||||
use Model\SettingMapper;
|
use Model\SettingMapper;
|
||||||
|
use Modules\Billing\Models\SettingsEnum;
|
||||||
use phpOMS\Application\ApplicationAbstract;
|
use phpOMS\Application\ApplicationAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,6 +46,6 @@ class Media
|
||||||
$defaultTemplate = \reset($media['upload'][0]);
|
$defaultTemplate = \reset($media['upload'][0]);
|
||||||
|
|
||||||
$setting = new Setting();
|
$setting = new Setting();
|
||||||
SettingMapper::create($setting->with(0, 'default_template', (string) $defaultTemplate->getId(), '\\d+', null, 'Billing'));
|
SettingMapper::create()->execute($setting->with(0, SettingsEnum::DEFAULT_SALES_INVOICE_TEMPLATE, (string) $defaultTemplate->getId(), '\\d+', null, 'Billing'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,41 +66,45 @@ final class Installer extends InstallerAbstract
|
||||||
{
|
{
|
||||||
$billType = [];
|
$billType = [];
|
||||||
|
|
||||||
|
// @todo: assign bill template here and not in the settings!!!
|
||||||
|
// @todo: allow multiple alternative bill templates
|
||||||
|
// @todo: implement ordering of templates
|
||||||
|
|
||||||
$billType['offer'] = new BillType('Offer');
|
$billType['offer'] = new BillType('Offer');
|
||||||
$billType['offer']->transferType = BillTransferType::SALES;
|
$billType['offer']->transferType = BillTransferType::SALES;
|
||||||
$billType['offer']->transferStock = false;
|
$billType['offer']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['offer']);
|
BillTypeMapper::create()->execute($billType['offer']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['order_confirmation'] = new BillType('Order Confirmation');
|
$billType['order_confirmation'] = new BillType('Order Confirmation');
|
||||||
$billType['order_confirmation']->transferType = BillTransferType::SALES;
|
$billType['order_confirmation']->transferType = BillTransferType::SALES;
|
||||||
$billType['order_confirmation']->transferStock = false;
|
$billType['order_confirmation']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['order_confirmation']);
|
BillTypeMapper::create()->execute($billType['order_confirmation']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['delivery_note'] = new BillType('Delivery Note');
|
$billType['delivery_note'] = new BillType('Delivery Note');
|
||||||
$billType['delivery_note']->transferType = BillTransferType::SALES;
|
$billType['delivery_note']->transferType = BillTransferType::SALES;
|
||||||
$billType['delivery_note']->transferStock = true;
|
$billType['delivery_note']->transferStock = true;
|
||||||
BillTypeMapper::create($billType['delivery_note']);
|
BillTypeMapper::create()->execute($billType['delivery_note']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['invoice'] = new BillType('Invoice');
|
$billType['invoice'] = new BillType('Invoice');
|
||||||
$billType['invoice']->transferType = BillTransferType::SALES;
|
$billType['invoice']->transferType = BillTransferType::SALES;
|
||||||
$billType['invoice']->transferStock = false;
|
$billType['invoice']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['invoice']);
|
BillTypeMapper::create()->execute($billType['invoice']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['credit_note'] = new BillType('Credit Note');
|
$billType['credit_note'] = new BillType('Credit Note');
|
||||||
$billType['credit_note']->transferType = BillTransferType::SALES;
|
$billType['credit_note']->transferType = BillTransferType::SALES;
|
||||||
$billType['credit_note']->transferStock = false;
|
$billType['credit_note']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['credit_note']);
|
BillTypeMapper::create()->execute($billType['credit_note']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['reverse_invoice'] = new BillType('Credit Note');
|
$billType['reverse_invoice'] = new BillType('Credit Note');
|
||||||
$billType['reverse_invoice']->transferType = BillTransferType::SALES;
|
$billType['reverse_invoice']->transferType = BillTransferType::SALES;
|
||||||
$billType['reverse_invoice']->transferStock = false;
|
$billType['reverse_invoice']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['reverse_invoice']);
|
BillTypeMapper::create()->execute($billType['reverse_invoice']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
return $billType;
|
return $billType;
|
||||||
}
|
}
|
||||||
|
|
@ -119,38 +123,38 @@ final class Installer extends InstallerAbstract
|
||||||
$billType['offer'] = new BillType('Offer');
|
$billType['offer'] = new BillType('Offer');
|
||||||
$billType['offer']->transferType = BillTransferType::PURCHASE;
|
$billType['offer']->transferType = BillTransferType::PURCHASE;
|
||||||
$billType['offer']->transferStock = false;
|
$billType['offer']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['offer']);
|
BillTypeMapper::create()->execute($billType['offer']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['order_confirmation'] = new BillType('Order Confirmation');
|
$billType['order_confirmation'] = new BillType('Order Confirmation');
|
||||||
$billType['order_confirmation']->transferType = BillTransferType::PURCHASE;
|
$billType['order_confirmation']->transferType = BillTransferType::PURCHASE;
|
||||||
$billType['order_confirmation']->transferStock = false;
|
$billType['order_confirmation']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['order_confirmation']);
|
BillTypeMapper::create()->execute($billType['order_confirmation']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['delivery_note'] = new BillType('Delivery Note');
|
$billType['delivery_note'] = new BillType('Delivery Note');
|
||||||
$billType['delivery_note']->transferType = BillTransferType::PURCHASE;
|
$billType['delivery_note']->transferType = BillTransferType::PURCHASE;
|
||||||
$billType['delivery_note']->transferStock = true;
|
$billType['delivery_note']->transferStock = true;
|
||||||
BillTypeMapper::create($billType['delivery_note']);
|
BillTypeMapper::create()->execute($billType['delivery_note']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['invoice'] = new BillType('Invoice');
|
$billType['invoice'] = new BillType('Invoice');
|
||||||
$billType['invoice']->transferType = BillTransferType::PURCHASE;
|
$billType['invoice']->transferType = BillTransferType::PURCHASE;
|
||||||
$billType['invoice']->transferStock = false;
|
$billType['invoice']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['invoice']);
|
BillTypeMapper::create()->execute($billType['invoice']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['credit_note'] = new BillType('Credit Note');
|
$billType['credit_note'] = new BillType('Credit Note');
|
||||||
$billType['credit_note']->transferType = BillTransferType::PURCHASE;
|
$billType['credit_note']->transferType = BillTransferType::PURCHASE;
|
||||||
$billType['credit_note']->transferStock = false;
|
$billType['credit_note']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['credit_note']);
|
BillTypeMapper::create()->execute($billType['credit_note']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
$billType['reverse_invoice'] = new BillType('Credit Note');
|
$billType['reverse_invoice'] = new BillType('Credit Note');
|
||||||
$billType['reverse_invoice']->transferType = BillTransferType::PURCHASE;
|
$billType['reverse_invoice']->transferType = BillTransferType::PURCHASE;
|
||||||
$billType['reverse_invoice']->transferStock = false;
|
$billType['reverse_invoice']->transferStock = false;
|
||||||
BillTypeMapper::create($billType['reverse_invoice']);
|
BillTypeMapper::create()->execute($billType['reverse_invoice']);
|
||||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
||||||
|
|
||||||
return $billType;
|
return $billType;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ use Modules\Billing\Models\BillElement;
|
||||||
use Modules\Billing\Models\BillElementMapper;
|
use Modules\Billing\Models\BillElementMapper;
|
||||||
use Modules\Billing\Models\BillMapper;
|
use Modules\Billing\Models\BillMapper;
|
||||||
use Modules\Billing\Models\NullBillType;
|
use Modules\Billing\Models\NullBillType;
|
||||||
|
use Modules\Billing\Models\SettingsEnum;
|
||||||
use Modules\ClientManagement\Models\ClientMapper;
|
use Modules\ClientManagement\Models\ClientMapper;
|
||||||
use Modules\ItemManagement\Models\ItemMapper;
|
use Modules\ItemManagement\Models\ItemMapper;
|
||||||
use Modules\Media\Models\CollectionMapper;
|
use Modules\Media\Models\CollectionMapper;
|
||||||
|
|
@ -91,9 +92,19 @@ final class ApiController extends Controller
|
||||||
{
|
{
|
||||||
$account = null;
|
$account = null;
|
||||||
if ($request->getData('client') !== null) {
|
if ($request->getData('client') !== null) {
|
||||||
$account = ClientMapper::get((int) $request->getData('client'));
|
$account = ClientMapper::get()
|
||||||
|
->with('profile')
|
||||||
|
->with('profile/account')
|
||||||
|
->with('mainAddress')
|
||||||
|
->where('id', (int) $request->getData('client'))
|
||||||
|
->execute();
|
||||||
} elseif ($request->getData('supplier') !== null) {
|
} elseif ($request->getData('supplier') !== null) {
|
||||||
$account = SupplierMapper::get((int) $request->getData('supplier'));
|
$account = SupplierMapper::get()
|
||||||
|
->with('profile')
|
||||||
|
->with('profile/account')
|
||||||
|
->with('mainAddress')
|
||||||
|
->where('id', (int) $request->getData('supplier'))
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @var \Modules\Account\Models\Account $account */
|
/* @var \Modules\Account\Models\Account $account */
|
||||||
|
|
@ -225,7 +236,7 @@ final class ApiController extends Controller
|
||||||
$element = $this->createBillElementFromRequest($request, $response, $data);
|
$element = $this->createBillElementFromRequest($request, $response, $data);
|
||||||
$this->createModel($request->header->account, $element, BillElementMapper::class, 'bill_element', $request->getOrigin());
|
$this->createModel($request->header->account, $element, BillElementMapper::class, 'bill_element', $request->getOrigin());
|
||||||
|
|
||||||
$old = BillMapper::get($element->bill);
|
$old = BillMapper::get()->where('id', $element->bill)->execute();
|
||||||
$new = $this->updateBillWithBillElement(clone $old, $element, 1);
|
$new = $this->updateBillWithBillElement(clone $old, $element, 1);
|
||||||
$this->updateModel($request->header->account, $old, $new, BillMapper::class, 'bill_element', $request->getOrigin());
|
$this->updateModel($request->header->account, $old, $new, BillMapper::class, 'bill_element', $request->getOrigin());
|
||||||
|
|
||||||
|
|
@ -254,7 +265,7 @@ final class ApiController extends Controller
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = ItemMapper::with('language', $response->getLanguage())::get($element->item);
|
$item = ItemMapper::get()->with('l11n')->where('id', $element->item)->where('l11n/language', $response->getLanguage())->execute();
|
||||||
$element->itemNumber = $item->number;
|
$element->itemNumber = $item->number;
|
||||||
$element->itemName = $item->getL11n('name1')->description;
|
$element->itemName = $item->getL11n('name1')->description;
|
||||||
$element->quantity = $request->getData('quantity', 'int');
|
$element->quantity = $request->getData('quantity', 'int');
|
||||||
|
|
@ -334,10 +345,14 @@ final class ApiController extends Controller
|
||||||
{
|
{
|
||||||
Autoloader::addPath(__DIR__ . '/../../../Resources/');
|
Autoloader::addPath(__DIR__ . '/../../../Resources/');
|
||||||
|
|
||||||
$bill = BillMapper::get($request->getData('bill'));
|
$bill = BillMapper::get()->where('id', $request->getData('bill'))->execute();
|
||||||
|
|
||||||
$defaultTemplate = $this->app->appSettings->get(null, 'default_template', null, self::NAME);
|
// @todo: change once bill types have media files/templates assigned
|
||||||
$template = CollectionMapper::get((int) $defaultTemplate->content);
|
$defaultTemplate = $this->app->appSettings->get(
|
||||||
|
names: SettingsEnum::DEFAULT_SALES_INVOICE_TEMPLATE,
|
||||||
|
module: self::NAME
|
||||||
|
);
|
||||||
|
$template = CollectionMapper::get()->where('id', (int) $defaultTemplate->content)->execute();
|
||||||
|
|
||||||
$pdfDir = __DIR__ . '/../../../Modules/Media/Files/Modules/Billing/Bills/'
|
$pdfDir = __DIR__ . '/../../../Modules/Media/Files/Modules/Billing/Bills/'
|
||||||
. $bill->createdAt->format('Y') . '/'
|
. $bill->createdAt->format('Y') . '/'
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,14 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Billing\Controller;
|
namespace Modules\Billing\Controller;
|
||||||
|
|
||||||
|
use Modules\Billing\Models\BillMapper;
|
||||||
use Modules\Billing\Models\BillTypeL11n;
|
use Modules\Billing\Models\BillTypeL11n;
|
||||||
use Modules\Billing\Models\PurchaseBillMapper;
|
use Modules\Billing\Models\PurchaseBillMapper;
|
||||||
use Modules\Billing\Models\SalesBillMapper;
|
use Modules\Billing\Models\SalesBillMapper;
|
||||||
use Modules\Billing\Models\StockBillMapper;
|
use Modules\Billing\Models\StockBillMapper;
|
||||||
use phpOMS\Asset\AssetType;
|
use phpOMS\Asset\AssetType;
|
||||||
use phpOMS\Contract\RenderableInterface;
|
use phpOMS\Contract\RenderableInterface;
|
||||||
|
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||||
use phpOMS\Localization\ISO3166CharEnum;
|
use phpOMS\Localization\ISO3166CharEnum;
|
||||||
use phpOMS\Localization\ISO3166NameEnum;
|
use phpOMS\Localization\ISO3166NameEnum;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
|
@ -57,18 +59,15 @@ final class BackendController extends Controller
|
||||||
|
|
||||||
if ($request->getData('ptype') === 'p') {
|
if ($request->getData('ptype') === 'p') {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
SalesBillMapper::getAll()->with('client')->where('id', (int) ($request->getData('id') ?? 0), '<')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
|
||||||
::getSalesBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
} elseif ($request->getData('ptype') === 'n') {
|
} elseif ($request->getData('ptype') === 'n') {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
SalesBillMapper::getAll()->with('client')->where('id', (int) ($request->getData('id') ?? 0), '>')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
|
||||||
::getSalesAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
SalesBillMapper::getAll()->with('client')->where('id', 0, '>')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
|
||||||
::getSalesAfterPivot(0, limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +92,7 @@ final class BackendController extends Controller
|
||||||
$view->setTemplate('/Modules/Billing/Theme/Backend/sales-bill');
|
$view->setTemplate('/Modules/Billing/Theme/Backend/sales-bill');
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005104001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005104001, $request, $response));
|
||||||
|
|
||||||
$bill = SalesBillMapper::get((int) $request->getData('id'));
|
$bill = SalesBillMapper::get()->with('elements')->where('id', (int) $request->getData('id'))->execute();
|
||||||
|
|
||||||
$view->setData('bill', $bill);
|
$view->setData('bill', $bill);
|
||||||
|
|
||||||
|
|
@ -183,18 +182,15 @@ final class BackendController extends Controller
|
||||||
|
|
||||||
if ($request->getData('ptype') === 'p') {
|
if ($request->getData('ptype') === 'p') {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
PurchaseBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
PurchaseBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute()
|
||||||
::getPurchaseBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
} elseif ($request->getData('ptype') === 'n') {
|
} elseif ($request->getData('ptype') === 'n') {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
PurchaseBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
PurchaseBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute()
|
||||||
::getPurchaseAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
PurchaseBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
PurchaseBillMapper::getAll()->where('id', 0, '>')->limit(25)->execute()
|
||||||
::getPurchaseAfterPivot(0, limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,7 +215,7 @@ final class BackendController extends Controller
|
||||||
$view->setTemplate('/Modules/Billing/Theme/Backend/purchase-bill');
|
$view->setTemplate('/Modules/Billing/Theme/Backend/purchase-bill');
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005104001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005104001, $request, $response));
|
||||||
|
|
||||||
$bill = PurchaseBillMapper::get((int) $request->getData('id'));
|
$bill = PurchaseBillMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||||
|
|
||||||
$view->setData('bill', $bill);
|
$view->setData('bill', $bill);
|
||||||
|
|
||||||
|
|
@ -246,18 +242,15 @@ final class BackendController extends Controller
|
||||||
|
|
||||||
if ($request->getData('ptype') === 'p') {
|
if ($request->getData('ptype') === 'p') {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
StockBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
StockBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute()
|
||||||
::getStockBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
} elseif ($request->getData('ptype') === 'n') {
|
} elseif ($request->getData('ptype') === 'n') {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
StockBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
StockBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute()
|
||||||
::getStockAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$view->setData('bills',
|
$view->setData('bills',
|
||||||
StockBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
StockBillMapper::getAll()->where('id', 0, '>')->limit(25)->execute()
|
||||||
::getStockAfterPivot(0, limit: 25, depth: 3)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,7 +275,7 @@ final class BackendController extends Controller
|
||||||
$view->setTemplate('/Modules/Billing/Theme/Backend/purchase-bill');
|
$view->setTemplate('/Modules/Billing/Theme/Backend/purchase-bill');
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005106001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005106001, $request, $response));
|
||||||
|
|
||||||
$bill = StockBillMapper::get((int) $request->getData('id'));
|
$bill = StockBillMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||||
|
|
||||||
$view->setData('bill', $bill);
|
$view->setData('bill', $bill);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use Modules\SupplierManagement\Models\Supplier;
|
||||||
use phpOMS\Localization\ISO4217CharEnum;
|
use phpOMS\Localization\ISO4217CharEnum;
|
||||||
use phpOMS\Localization\Money;
|
use phpOMS\Localization\Money;
|
||||||
use Modules\Editor\Models\EditorDoc;
|
use Modules\Editor\Models\EditorDoc;
|
||||||
|
use Modules\Media\Models\NullMedia;
|
||||||
use Mpdf\Tag\P;
|
use Mpdf\Tag\P;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -715,6 +716,27 @@ class Bill implements \JsonSerializable
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get media file by type
|
||||||
|
*
|
||||||
|
* @param null|int $type Media type
|
||||||
|
*
|
||||||
|
* @return Media
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getFileByType(int $type = null) : Media
|
||||||
|
{
|
||||||
|
$files = [];
|
||||||
|
foreach ($this->media as $file) {
|
||||||
|
if ($file->type === $type) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NullMedia();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Billing\Models;
|
namespace Modules\Billing\Models;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapper class.
|
* Mapper class.
|
||||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
final class BillElementMapper extends DataMapperAbstract
|
final class BillElementMapper extends DataMapperFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
|
|
@ -32,7 +32,7 @@ final class BillElementMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $columns = [
|
public const COLUMNS = [
|
||||||
'billing_bill_element_id' => ['name' => 'billing_bill_element_id', 'type' => 'int', 'internal' => 'id'],
|
'billing_bill_element_id' => ['name' => 'billing_bill_element_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'billing_bill_element_order' => ['name' => 'billing_bill_element_order', 'type' => 'int', 'internal' => 'order'],
|
'billing_bill_element_order' => ['name' => 'billing_bill_element_order', 'type' => 'int', 'internal' => 'order'],
|
||||||
'billing_bill_element_item' => ['name' => 'billing_bill_element_item', 'type' => 'int', 'internal' => 'item'],
|
'billing_bill_element_item' => ['name' => 'billing_bill_element_item', 'type' => 'int', 'internal' => 'item'],
|
||||||
|
|
@ -69,7 +69,7 @@ final class BillElementMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{mapper:string, external:string}>
|
* @var array<string, array{mapper:string, external:string}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $belongsTo = [
|
public const BELONGS_TO = [
|
||||||
'bill' => [
|
'bill' => [
|
||||||
'mapper' => BillMapper::class,
|
'mapper' => BillMapper::class,
|
||||||
'external' => 'billing_bill_element_bill',
|
'external' => 'billing_bill_element_bill',
|
||||||
|
|
@ -82,7 +82,7 @@ final class BillElementMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static string $primaryField = 'billing_bill_element_id';
|
public const PRIMARYFIELD = 'billing_bill_element_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary table.
|
* Primary table.
|
||||||
|
|
@ -90,5 +90,5 @@ final class BillElementMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static string $table = 'billing_bill_element';
|
public const TABLE = 'billing_bill_element';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use Modules\Admin\Models\AccountMapper;
|
||||||
use Modules\ClientManagement\Models\ClientMapper;
|
use Modules\ClientManagement\Models\ClientMapper;
|
||||||
use Modules\Media\Models\MediaMapper;
|
use Modules\Media\Models\MediaMapper;
|
||||||
use Modules\SupplierManagement\Models\SupplierMapper;
|
use Modules\SupplierManagement\Models\SupplierMapper;
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
use Modules\Editor\Models\EditorDocMapper;
|
use Modules\Editor\Models\EditorDocMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,7 +29,7 @@ use Modules\Editor\Models\EditorDocMapper;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class BillMapper extends DataMapperAbstract
|
class BillMapper extends DataMapperFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
|
|
@ -37,7 +37,7 @@ class BillMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $columns = [
|
public const COLUMNS = [
|
||||||
'billing_bill_id' => ['name' => 'billing_bill_id', 'type' => 'int', 'internal' => 'id'],
|
'billing_bill_id' => ['name' => 'billing_bill_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'billing_bill_number' => ['name' => 'billing_bill_number', 'type' => 'string', 'internal' => 'number'],
|
'billing_bill_number' => ['name' => 'billing_bill_number', 'type' => 'string', 'internal' => 'number'],
|
||||||
'billing_bill_numberformat' => ['name' => 'billing_bill_numberformat', 'type' => 'string', 'internal' => 'numberFormat'],
|
'billing_bill_numberformat' => ['name' => 'billing_bill_numberformat', 'type' => 'string', 'internal' => 'numberFormat'],
|
||||||
|
|
@ -87,7 +87,7 @@ class BillMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $hasMany = [
|
public const HAS_MANY = [
|
||||||
'elements' => [
|
'elements' => [
|
||||||
'mapper' => BillElementMapper::class,
|
'mapper' => BillElementMapper::class,
|
||||||
'table' => 'billing_bill_element',
|
'table' => 'billing_bill_element',
|
||||||
|
|
@ -114,7 +114,7 @@ class BillMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $ownsOne = [
|
public const OWNS_ONE = [
|
||||||
'type' => [
|
'type' => [
|
||||||
'mapper' => BillTypeMapper::class,
|
'mapper' => BillTypeMapper::class,
|
||||||
'external' => 'billing_bill_type',
|
'external' => 'billing_bill_type',
|
||||||
|
|
@ -131,7 +131,7 @@ class BillMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{mapper:string, external:string}>
|
* @var array<string, array{mapper:string, external:string}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $belongsTo = [
|
public const BELONGS_TO = [
|
||||||
'createdBy' => [
|
'createdBy' => [
|
||||||
'mapper' => AccountMapper::class,
|
'mapper' => AccountMapper::class,
|
||||||
'external' => 'billing_bill_created_by',
|
'external' => 'billing_bill_created_by',
|
||||||
|
|
@ -152,7 +152,7 @@ class BillMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $primaryField = 'billing_bill_id';
|
public const PRIMARYFIELD ='billing_bill_id';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary table.
|
* Primary table.
|
||||||
|
|
@ -160,5 +160,5 @@ class BillMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $table = 'billing_bill';
|
public const TABLE = 'billing_bill';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Billing\Models;
|
namespace Modules\Billing\Models;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bill type mapper class.
|
* Bill type mapper class.
|
||||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
final class BillTypeL11nMapper extends DataMapperAbstract
|
final class BillTypeL11nMapper extends DataMapperFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
|
|
@ -32,7 +32,7 @@ final class BillTypeL11nMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $columns = [
|
public const COLUMNS = [
|
||||||
'billing_type_l11n_id' => ['name' => 'billing_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
'billing_type_l11n_id' => ['name' => 'billing_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'billing_type_l11n_name' => ['name' => 'billing_type_l11n_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
'billing_type_l11n_name' => ['name' => 'billing_type_l11n_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||||
'billing_type_l11n_type' => ['name' => 'billing_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
|
'billing_type_l11n_type' => ['name' => 'billing_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
|
||||||
|
|
@ -45,7 +45,7 @@ final class BillTypeL11nMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $table = 'billing_type_l11n';
|
public const TABLE = 'billing_type_l11n';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary field name.
|
* Primary field name.
|
||||||
|
|
@ -53,5 +53,5 @@ final class BillTypeL11nMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $primaryField = 'billing_type_l11n_id';
|
public const PRIMARYFIELD ='billing_type_l11n_id';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Billing\Models;
|
namespace Modules\Billing\Models;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Billing mapper class.
|
* Billing mapper class.
|
||||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
final class BillTypeMapper extends DataMapperAbstract
|
final class BillTypeMapper extends DataMapperFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Columns.
|
* Columns.
|
||||||
|
|
@ -32,7 +32,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $columns = [
|
public const COLUMNS = [
|
||||||
'billing_type_id' => ['name' => 'billing_type_id', 'type' => 'int', 'internal' => 'id'],
|
'billing_type_id' => ['name' => 'billing_type_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'billing_type_transfer_type' => ['name' => 'billing_type_transfer_type', 'type' => 'int', 'internal' => 'transferType'],
|
'billing_type_transfer_type' => ['name' => 'billing_type_transfer_type', 'type' => 'int', 'internal' => 'transferType'],
|
||||||
'billing_type_transfer_stock' => ['name' => 'billing_type_transfer_stock', 'type' => 'bool', 'internal' => 'transferStock'],
|
'billing_type_transfer_stock' => ['name' => 'billing_type_transfer_stock', 'type' => 'bool', 'internal' => 'transferStock'],
|
||||||
|
|
@ -44,13 +44,12 @@ final class BillTypeMapper extends DataMapperAbstract
|
||||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static array $hasMany = [
|
public const HAS_MANY = [
|
||||||
'l11n' => [
|
'l11n' => [
|
||||||
'mapper' => BillTypeL11nMapper::class,
|
'mapper' => BillTypeL11nMapper::class,
|
||||||
'table' => 'billing_type_l11n',
|
'table' => 'billing_type_l11n',
|
||||||
'self' => 'billing_type_l11n_type',
|
'self' => 'billing_type_l11n_type',
|
||||||
'column' => 'name',
|
'column' => 'name',
|
||||||
'conditional' => true,
|
|
||||||
'external' => null,
|
'external' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
@ -62,7 +61,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
protected static array $belongsTo = [
|
public const BELONGS_TO = [
|
||||||
'owner' => [
|
'owner' => [
|
||||||
'mapper' => AccountMapper::class,
|
'mapper' => AccountMapper::class,
|
||||||
'external' => 'billing_type_owner',
|
'external' => 'billing_type_owner',
|
||||||
|
|
@ -76,7 +75,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $model = BillType::class;
|
public const MODEL = BillType::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary table.
|
* Primary table.
|
||||||
|
|
@ -84,7 +83,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $table = 'billing_type';
|
public const TABLE = 'billing_type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primary field name.
|
* Primary field name.
|
||||||
|
|
@ -92,5 +91,5 @@ final class BillTypeMapper extends DataMapperAbstract
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $primaryField = 'billing_type_id';
|
public const PRIMARYFIELD ='billing_type_id';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ namespace Modules\Billing\Models;
|
||||||
|
|
||||||
use Modules\SupplierManagement\Models\SupplierMapper;
|
use Modules\SupplierManagement\Models\SupplierMapper;
|
||||||
use phpOMS\DataStorage\Database\Query\Builder;
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
use phpOMS\DataStorage\Database\RelationType;
|
|
||||||
use phpOMS\Localization\Defaults\CountryMapper;
|
use phpOMS\Localization\Defaults\CountryMapper;
|
||||||
use phpOMS\Localization\Money;
|
use phpOMS\Localization\Money;
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $model = Bill::class;
|
public const MODEL = Bill::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder
|
* Placeholder
|
||||||
|
|
@ -45,15 +44,16 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
mixed $pivot,
|
mixed $pivot,
|
||||||
string $column = null,
|
string $column = null,
|
||||||
int $limit = 50,
|
int $limit = 50,
|
||||||
int $relations = RelationType::ALL,
|
|
||||||
int $depth = 3,
|
int $depth = 3,
|
||||||
Builder $query = null
|
Builder $query = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$query = self::getQuery(null, [], $relations, $depth);
|
return self::getAll()
|
||||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::PURCHASE);
|
->with('type')
|
||||||
|
->where('id', $pivot, '<')
|
||||||
return self::getBeforePivot($pivot, $column, $limit, $relations, $depth, $query);
|
->where('transferType', BillTransferType::PURCHASE)
|
||||||
|
->limit($limit)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,15 +63,16 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
mixed $pivot,
|
mixed $pivot,
|
||||||
string $column = null,
|
string $column = null,
|
||||||
int $limit = 50,
|
int $limit = 50,
|
||||||
int $relations = RelationType::ALL,
|
|
||||||
int $depth = 3,
|
int $depth = 3,
|
||||||
Builder $query = null
|
Builder $query = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$query = self::getQuery(null, [], $relations, $depth);
|
return self::getAll()
|
||||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::PURCHASE);
|
->with('type')
|
||||||
|
->where('id', $pivot, '>')
|
||||||
return self::getAfterPivot($pivot, $column, $limit, $relations, $depth, $query);
|
->where('transferType', BillTransferType::PURCHASE)
|
||||||
|
->limit($limit)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,12 +82,12 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('SUM(billing_bill_element_total_netpurchaseprice)')
|
$result = $query->select('SUM(billing_bill_element_total_netpurchaseprice)')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->execute()
|
->execute()
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
|
|
@ -100,10 +101,10 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('SUM(billing_bill_netcosts)')
|
$result = $query->select('SUM(billing_bill_netcosts)')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->where(self::$table . '.billing_bill_supplier', '=', $id)
|
->where(self::TABLE . '.billing_bill_supplier', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->execute()
|
->execute()
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
|
|
@ -117,12 +118,12 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('SUM(billing_bill_element_single_netpurchaseprice)', 'COUNT(billing_bill_element_total_netpurchaseprice)')
|
$result = $query->select('SUM(billing_bill_element_single_netpurchaseprice)', 'COUNT(billing_bill_element_total_netpurchaseprice)')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->execute()
|
->execute()
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
|
|
@ -137,10 +138,10 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
// @todo: only delivers/invoice/production (no offers ...)
|
// @todo: only delivers/invoice/production (no offers ...)
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('billing_bill_performance_date')
|
$result = $query->select('billing_bill_performance_date')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->orderBy('billing_bill_id', 'DESC')
|
->orderBy('billing_bill_id', 'DESC')
|
||||||
->limit(1)
|
->limit(1)
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -157,8 +158,8 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
// @todo: only delivers/invoice/production (no offers ...)
|
// @todo: only delivers/invoice/production (no offers ...)
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('billing_bill_performance_date')
|
$result = $query->select('billing_bill_performance_date')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->where(self::$table . '.billing_bill_supplier', '=', $id)
|
->where(self::TABLE . '.billing_bill_supplier', '=', $id)
|
||||||
->orderBy('billing_bill_id', 'DESC')
|
->orderBy('billing_bill_id', 'DESC')
|
||||||
->limit(1)
|
->limit(1)
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -188,23 +189,22 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getNewestItemInvoices(int $id, int $limit = 10) : array
|
public static function getNewestItemInvoices(int $id, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
||||||
|
|
||||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
$query = self::getQuery();
|
||||||
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||||
->limit($limit);
|
->limit($limit);
|
||||||
|
|
||||||
if (!empty(self::$createdAt)) {
|
if (!empty(self::CREATED_AT)) {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$primaryField]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::PRIMARYFIELD]['name'], 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
return self::getAll()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,21 +212,20 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getNewestSupplierInvoices(int $id, int $limit = 10) : array
|
public static function getNewestSupplierInvoices(int $id, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
||||||
|
|
||||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
$query = self::getQuery();
|
||||||
$query->where(self::$table . '_d' . $depth . '.billing_bill_supplier', '=', $id)
|
$query->where(self::TABLE . '_d1.billing_bill_supplier', '=', $id)
|
||||||
->limit($limit);
|
->limit($limit);
|
||||||
|
|
||||||
if (!empty(self::$createdAt)) {
|
if (!empty(self::CREATED_AT)) {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$primaryField]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::PRIMARYFIELD]['name'], 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
return self::getAll()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -234,23 +233,22 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getItemTopSuppliers(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array
|
public static function getItemTopSuppliers(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
$query = SupplierMapper::getQuery(null, [], RelationType::ALL, $depth);
|
$query = SupplierMapper::getQuery();
|
||||||
$query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
$query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
||||||
->leftJoin(self::$table, self::$table . '_d' . $depth)
|
->leftJoin(self::TABLE, self::TABLE . '_d1')
|
||||||
->on(SupplierMapper::getTable() . '_d' . $depth . '.suppliermgmt_supplier_id', '=', self::$table . '_d' . $depth . '.billing_bill_supplier')
|
->on(SupplierMapper::TABLE . '_d1.suppliermgmt_supplier_id', '=', self::TABLE . '_d1.billing_bill_supplier')
|
||||||
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '<=', $end)
|
||||||
->orderBy('net_purchase', 'DESC')
|
->orderBy('net_purchase', 'DESC')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->groupBy(SupplierMapper::getTable() . '_d' . $depth . '.suppliermgmt_supplier_id');
|
->groupBy(SupplierMapper::TABLE . '_d1.suppliermgmt_supplier_id');
|
||||||
|
|
||||||
$suppliers = SupplierMapper::getAllByQuery($query, RelationType::ALL, $depth);
|
$suppliers = SupplierMapper::getAll()->execute($query);
|
||||||
$data = SupplierMapper::getDataLastQuery();
|
$data = SupplierMapper::getRaw()->execute();
|
||||||
|
|
||||||
return [$suppliers, $data];
|
return [$suppliers, $data];
|
||||||
}
|
}
|
||||||
|
|
@ -261,17 +259,17 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
public static function getItemRegionPurchase(int $id, \DateTime $start, \DateTime $end) : array
|
public static function getItemRegionPurchase(int $id, \DateTime $start, \DateTime $end) : array
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select(CountryMapper::getTable() . '.country_region')
|
$result = $query->select(CountryMapper::TABLE . '.country_region')
|
||||||
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->leftJoin(CountryMapper::getTable())
|
->leftJoin(CountryMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy(CountryMapper::getTable() . '.country_region')
|
->groupBy(CountryMapper::TABLE . '.country_region')
|
||||||
->execute()
|
->execute()
|
||||||
->fetchAll(\PDO::FETCH_KEY_PAIR);
|
->fetchAll(\PDO::FETCH_KEY_PAIR);
|
||||||
|
|
||||||
|
|
@ -284,17 +282,17 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
public static function getItemCountryPurchase(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array
|
public static function getItemCountryPurchase(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select(CountryMapper::getTable() . '.country_code2')
|
$result = $query->select(CountryMapper::TABLE . '.country_code2')
|
||||||
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->leftJoin(CountryMapper::getTable())
|
->leftJoin(CountryMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy(CountryMapper::getTable() . '.country_code2')
|
->groupBy(CountryMapper::TABLE . '.country_code2')
|
||||||
->orderBy('net_purchase', 'DESC')
|
->orderBy('net_purchase', 'DESC')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -312,12 +310,12 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
$result = $query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
$result = $query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
||||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy('year', 'month')
|
->groupBy('year', 'month')
|
||||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -335,10 +333,10 @@ final class PurchaseBillMapper extends BillMapper
|
||||||
$result = $query->selectAs('SUM(billing_bill_netcosts)', 'net_purchase')
|
$result = $query->selectAs('SUM(billing_bill_netcosts)', 'net_purchase')
|
||||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->where(self::$table . '.billing_bill_supplier', '=', $id)
|
->where(self::TABLE . '.billing_bill_supplier', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy('year', 'month')
|
->groupBy('year', 'month')
|
||||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||||
->execute()
|
->execute()
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ namespace Modules\Billing\Models;
|
||||||
|
|
||||||
use Modules\ClientManagement\Models\ClientMapper;
|
use Modules\ClientManagement\Models\ClientMapper;
|
||||||
use phpOMS\DataStorage\Database\Query\Builder;
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
use phpOMS\DataStorage\Database\RelationType;
|
|
||||||
use phpOMS\Localization\Defaults\CountryMapper;
|
use phpOMS\Localization\Defaults\CountryMapper;
|
||||||
use phpOMS\Localization\Money;
|
use phpOMS\Localization\Money;
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@ final class SalesBillMapper extends BillMapper
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $model = Bill::class;
|
public const MODEL = Bill::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder
|
* Placeholder
|
||||||
|
|
@ -45,15 +44,16 @@ final class SalesBillMapper extends BillMapper
|
||||||
mixed $pivot,
|
mixed $pivot,
|
||||||
string $column = null,
|
string $column = null,
|
||||||
int $limit = 50,
|
int $limit = 50,
|
||||||
int $relations = RelationType::ALL,
|
|
||||||
int $depth = 3,
|
int $depth = 3,
|
||||||
Builder $query = null
|
Builder $query = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$query = self::getQuery(null, [], $relations, $depth);
|
return self::getAll()
|
||||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::SALES);
|
->with('type')
|
||||||
|
->where('id', $pivot, '<')
|
||||||
return self::getBeforePivot($pivot, $column, $limit, $relations, $depth, $query);
|
->where('transferType', BillTransferType::SALES)
|
||||||
|
->limit($limit)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,15 +63,16 @@ final class SalesBillMapper extends BillMapper
|
||||||
mixed $pivot,
|
mixed $pivot,
|
||||||
string $column = null,
|
string $column = null,
|
||||||
int $limit = 50,
|
int $limit = 50,
|
||||||
int $relations = RelationType::ALL,
|
|
||||||
int $depth = 3,
|
int $depth = 3,
|
||||||
Builder $query = null
|
Builder $query = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$query = self::getQuery(null, [], $relations, $depth);
|
return self::getAll()
|
||||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::SALES);
|
->with('type')
|
||||||
|
->where('id', $pivot, '>')
|
||||||
return self::getAfterPivot($pivot, $column, $limit, $relations, $depth, $query);
|
->where('transferType', BillTransferType::SALES)
|
||||||
|
->limit($limit)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,12 +82,12 @@ final class SalesBillMapper extends BillMapper
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('SUM(billing_bill_element_total_netsalesprice)')
|
$result = $query->select('SUM(billing_bill_element_total_netsalesprice)')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->execute()
|
->execute()
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
|
|
@ -100,10 +101,10 @@ final class SalesBillMapper extends BillMapper
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('SUM(billing_bill_netsales)')
|
$result = $query->select('SUM(billing_bill_netsales)')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->where(self::$table . '.billing_bill_client', '=', $id)
|
->where(self::TABLE . '.billing_bill_client', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->execute()
|
->execute()
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
|
|
@ -117,12 +118,12 @@ final class SalesBillMapper extends BillMapper
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('SUM(billing_bill_element_single_netsalesprice)', 'COUNT(billing_bill_element_total_netsalesprice)')
|
$result = $query->select('SUM(billing_bill_element_single_netsalesprice)', 'COUNT(billing_bill_element_total_netsalesprice)')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->execute()
|
->execute()
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
|
|
@ -137,10 +138,10 @@ final class SalesBillMapper extends BillMapper
|
||||||
// @todo: only delivers/invoice/production (no offers ...)
|
// @todo: only delivers/invoice/production (no offers ...)
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('billing_bill_performance_date')
|
$result = $query->select('billing_bill_performance_date')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->orderBy('billing_bill_id', 'DESC')
|
->orderBy('billing_bill_id', 'DESC')
|
||||||
->limit(1)
|
->limit(1)
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -157,8 +158,8 @@ final class SalesBillMapper extends BillMapper
|
||||||
// @todo: only delivers/invoice/production (no offers ...)
|
// @todo: only delivers/invoice/production (no offers ...)
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select('billing_bill_performance_date')
|
$result = $query->select('billing_bill_performance_date')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->where(self::$table . '.billing_bill_client', '=', $id)
|
->where(self::TABLE . '.billing_bill_client', '=', $id)
|
||||||
->orderBy('billing_bill_id', 'DESC')
|
->orderBy('billing_bill_id', 'DESC')
|
||||||
->limit(1)
|
->limit(1)
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -188,23 +189,22 @@ final class SalesBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getNewestItemInvoices(int $id, int $limit = 10) : array
|
public static function getNewestItemInvoices(int $id, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
||||||
|
|
||||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
$query = self::getQuery();
|
||||||
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||||
->limit($limit);
|
->limit($limit);
|
||||||
|
|
||||||
if (!empty(self::$createdAt)) {
|
if (!empty(self::CREATED_AT)) {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$primaryField]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::PRIMARYFIELD]['name'], 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
return self::getAll()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,21 +212,20 @@ final class SalesBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getNewestClientInvoices(int $id, int $limit = 10) : array
|
public static function getNewestClientInvoices(int $id, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
||||||
|
|
||||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
$query = self::getQuery();
|
||||||
$query->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $id)
|
$query->where(self::TABLE . '_d1.billing_bill_client', '=', $id)
|
||||||
->limit($limit);
|
->limit($limit);
|
||||||
|
|
||||||
if (!empty(self::$createdAt)) {
|
if (!empty(self::CREATED_AT)) {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$primaryField]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::PRIMARYFIELD]['name'], 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
return self::getAll()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -234,23 +233,22 @@ final class SalesBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getItemTopClients(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;
|
|
||||||
|
|
||||||
$query = ClientMapper::getQuery(null, [], RelationType::ALL, $depth);
|
$query = ClientMapper::getQuery();
|
||||||
$query->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
$query->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
||||||
->leftJoin(self::$table, self::$table . '_d' . $depth)
|
->leftJoin(self::TABLE, self::TABLE . '_d1')
|
||||||
->on(ClientMapper::getTable() . '_d' . $depth . '.clientmgmt_client_id', '=', self::$table . '_d' . $depth . '.billing_bill_client')
|
->on(ClientMapper::TABLE . '_d1.clientmgmt_client_id', '=', self::TABLE . '_d1.billing_bill_client')
|
||||||
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '<=', $end)
|
||||||
->orderBy('net_sales', 'DESC')
|
->orderBy('net_sales', 'DESC')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->groupBy(ClientMapper::getTable() . '_d' . $depth . '.clientmgmt_client_id');
|
->groupBy(ClientMapper::TABLE . '_d1.clientmgmt_client_id');
|
||||||
|
|
||||||
$clients = ClientMapper::getAllByQuery($query, RelationType::ALL, $depth);
|
$clients = ClientMapper::getAll()->execute($query);
|
||||||
$data = ClientMapper::getDataLastQuery();
|
$data = ClientMapper::getRaw()->execute();
|
||||||
|
|
||||||
return [$clients, $data];
|
return [$clients, $data];
|
||||||
}
|
}
|
||||||
|
|
@ -260,23 +258,22 @@ final class SalesBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getItemBills(int $id, \DateTime $start, \DateTime $end) : array
|
public static function getItemBills(int $id, \DateTime $start, \DateTime $end) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
||||||
|
|
||||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
$query = self::getQuery();
|
||||||
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||||
->limit($limit = 10);
|
->limit($limit = 10);
|
||||||
|
|
||||||
if (!empty(self::$createdAt)) {
|
if (!empty(self::CREATED_AT)) {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$primaryField]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::PRIMARYFIELD]['name'], 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
return self::getAll()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -284,23 +281,22 @@ final class SalesBillMapper extends BillMapper
|
||||||
*/
|
*/
|
||||||
public static function getClientItem(int $client, \DateTime $start, \DateTime $end) : array
|
public static function getClientItem(int $client, \DateTime $start, \DateTime $end) : array
|
||||||
{
|
{
|
||||||
$depth = 3;
|
|
||||||
|
|
||||||
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
// @todo: limit is not working correctly... only returns / 2 or something like that?. Maybe because bills arent unique?
|
||||||
|
|
||||||
$query = BillElementMapper::getQuery(null, [], RelationType::ALL, $depth);
|
$query = BillElementMapper::getQuery();
|
||||||
$query->leftJoin(self::$table, self::$table . '_d' . $depth)
|
$query->leftJoin(self::TABLE, self::TABLE . '_d1')
|
||||||
->on(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill', '=', self::$table . '_d' . $depth . '.billing_bill_id')
|
->on(BillElementMapper::TABLE . '_d1.billing_bill_element_bill', '=', self::TABLE . '_d1.billing_bill_id')
|
||||||
->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $client)
|
->where(self::TABLE . '_d1.billing_bill_client', '=', $client)
|
||||||
->limit($limit = 10);
|
->limit($limit = 10);
|
||||||
|
|
||||||
if (!empty(self::$createdAt)) {
|
if (!empty(self::CREATED_AT)) {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$primaryField]['name'], 'DESC');
|
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::PRIMARYFIELD]['name'], 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
return BillElementMapper::getAllByQuery($query, RelationType::ALL, $depth);
|
return BillElementMapper::getAll()->execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -309,17 +305,17 @@ final class SalesBillMapper extends BillMapper
|
||||||
public static function getItemRegionSales(int $id, \DateTime $start, \DateTime $end) : array
|
public static function getItemRegionSales(int $id, \DateTime $start, \DateTime $end) : array
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select(CountryMapper::getTable() . '.country_region')
|
$result = $query->select(CountryMapper::TABLE . '.country_region')
|
||||||
->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->leftJoin(CountryMapper::getTable())
|
->leftJoin(CountryMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy(CountryMapper::getTable() . '.country_region')
|
->groupBy(CountryMapper::TABLE . '.country_region')
|
||||||
->execute()
|
->execute()
|
||||||
->fetchAll(\PDO::FETCH_KEY_PAIR);
|
->fetchAll(\PDO::FETCH_KEY_PAIR);
|
||||||
|
|
||||||
|
|
@ -332,17 +328,17 @@ final class SalesBillMapper extends BillMapper
|
||||||
public static function getItemCountrySales(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array
|
public static function getItemCountrySales(int $id, \DateTime $start, \DateTime $end, int $limit = 10) : array
|
||||||
{
|
{
|
||||||
$query = new Builder(self::$db);
|
$query = new Builder(self::$db);
|
||||||
$result = $query->select(CountryMapper::getTable() . '.country_code2')
|
$result = $query->select(CountryMapper::TABLE . '.country_code2')
|
||||||
->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->leftJoin(CountryMapper::getTable())
|
->leftJoin(CountryMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy(CountryMapper::getTable() . '.country_code2')
|
->groupBy(CountryMapper::TABLE . '.country_code2')
|
||||||
->orderBy('net_sales', 'DESC')
|
->orderBy('net_sales', 'DESC')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -361,12 +357,12 @@ final class SalesBillMapper extends BillMapper
|
||||||
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_costs')
|
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_costs')
|
||||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->leftJoin(BillElementMapper::getTable())
|
->leftJoin(BillElementMapper::TABLE)
|
||||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy('year', 'month')
|
->groupBy('year', 'month')
|
||||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||||
->execute()
|
->execute()
|
||||||
|
|
@ -385,10 +381,10 @@ final class SalesBillMapper extends BillMapper
|
||||||
->selectAs('SUM(billing_bill_netcosts)', 'net_costs')
|
->selectAs('SUM(billing_bill_netcosts)', 'net_costs')
|
||||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||||
->from(self::$table)
|
->from(self::TABLE)
|
||||||
->where(self::$table . '.billing_bill_client', '=', $id)
|
->where(self::TABLE . '.billing_bill_client', '=', $id)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||||
->groupBy('year', 'month')
|
->groupBy('year', 'month')
|
||||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||||
->execute()
|
->execute()
|
||||||
|
|
|
||||||
|
|
@ -26,5 +26,5 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class SettingsEnum extends Enum
|
abstract class SettingsEnum extends Enum
|
||||||
{
|
{
|
||||||
|
public const DEFAULT_SALES_INVOICE_TEMPLATE = '1005100001_1';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
||||||
namespace Modules\Billing\Models;
|
namespace Modules\Billing\Models;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\Query\Builder;
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
use phpOMS\DataStorage\Database\RelationType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapper class.
|
* Mapper class.
|
||||||
|
|
@ -33,7 +32,7 @@ final class StockBillMapper extends BillMapper
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected static string $model = Bill::class;
|
public const MODEL = Bill::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placeholder
|
* Placeholder
|
||||||
|
|
@ -42,15 +41,16 @@ final class StockBillMapper extends BillMapper
|
||||||
mixed $pivot,
|
mixed $pivot,
|
||||||
string $column = null,
|
string $column = null,
|
||||||
int $limit = 50,
|
int $limit = 50,
|
||||||
int $relations = RelationType::ALL,
|
|
||||||
int $depth = 3,
|
int $depth = 3,
|
||||||
Builder $query = null
|
Builder $query = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$query = self::getQuery(null, [], $relations, $depth);
|
return self::getAll()
|
||||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::STOCK);
|
->with('type')
|
||||||
|
->where('id', $pivot, '<')
|
||||||
return self::getBeforePivot($pivot, $column, $limit, $relations, $depth, $query);
|
->where('transferType', BillTransferType::SALES)
|
||||||
|
->limit($limit)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,14 +60,15 @@ final class StockBillMapper extends BillMapper
|
||||||
mixed $pivot,
|
mixed $pivot,
|
||||||
string $column = null,
|
string $column = null,
|
||||||
int $limit = 50,
|
int $limit = 50,
|
||||||
int $relations = RelationType::ALL,
|
|
||||||
int $depth = 3,
|
int $depth = 3,
|
||||||
Builder $query = null
|
Builder $query = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
$query = self::getQuery(null, [], $relations, $depth);
|
return self::getAll()
|
||||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::STOCK);
|
->with('type')
|
||||||
|
->where('id', $pivot, '>')
|
||||||
return self::getAfterPivot($pivot, $column, $limit, $relations, $depth, $query);
|
->where('transferType', BillTransferType::SALES)
|
||||||
|
->limit($limit)
|
||||||
|
->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ use phpOMS\Uri\UriFactory;
|
||||||
/**
|
/**
|
||||||
* @var \phpOMS\Views\View $this
|
* @var \phpOMS\Views\View $this
|
||||||
*/
|
*/
|
||||||
|
/** @var Modules\Billing\Models\Bill $bill */
|
||||||
$bill = $this->getData('bill');
|
$bill = $this->getData('bill');
|
||||||
$elements = $bill->getElements();
|
$elements = $bill->getElements();
|
||||||
|
|
||||||
$billPdf = $bill->getMediaByType('bill');
|
$billPdf = $bill->getFileByType(0);
|
||||||
|
|
||||||
echo $this->getData('nav')->render(); ?>
|
echo $this->getData('nav')->render(); ?>
|
||||||
|
|
||||||
|
|
@ -179,9 +179,9 @@ echo $this->getData('nav')->render(); ?>
|
||||||
</table>
|
</table>
|
||||||
<div class="portlet-foot">
|
<div class="portlet-foot">
|
||||||
<?= $this->getHtml('Freightage'); ?>: 0.00 -
|
<?= $this->getHtml('Freightage'); ?>: 0.00 -
|
||||||
<?= $this->getHtml('Net'); ?>: <?= $bill->net->getCurrency(); ?> -
|
<?= $this->getHtml('Net'); ?>: <?= $bill->netSales->getCurrency(); ?> -
|
||||||
<?= $this->getHtml('Tax'); ?>: 0.00 -
|
<?= $this->getHtml('Tax'); ?>: 0.00 -
|
||||||
<?= $this->getHtml('Total'); ?>: <?= $bill->gross->getCurrency(); ?>
|
<?= $this->getHtml('Total'); ?>: <?= $bill->grossSales->getCurrency(); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
require_once __DIR__ . '/Autoloader.php';
|
require_once __DIR__ . '/Autoloader.php';
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\DatabasePool;
|
use phpOMS\DataStorage\Database\DatabasePool;
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
use phpOMS\DataStorage\Session\HttpSession;
|
use phpOMS\DataStorage\Session\HttpSession;
|
||||||
|
|
||||||
$CONFIG = [
|
$CONFIG = [
|
||||||
|
|
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
|
||||||
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
|
||||||
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||||
|
|
||||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||||
|
|
||||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user