mirror of
https://github.com/Karaka-Management/oms-Billing.git
synced 2026-02-01 09:18:42 +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\SettingMapper;
|
||||
use Modules\Billing\Models\SettingsEnum;
|
||||
use phpOMS\Application\ApplicationAbstract;
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +46,6 @@ class Media
|
|||
$defaultTemplate = \reset($media['upload'][0]);
|
||||
|
||||
$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 = [];
|
||||
|
||||
// @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']->transferType = BillTransferType::SALES;
|
||||
$billType['offer']->transferStock = false;
|
||||
BillTypeMapper::create($billType['offer']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['offer']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['order_confirmation'] = new BillType('Order Confirmation');
|
||||
$billType['order_confirmation']->transferType = BillTransferType::SALES;
|
||||
$billType['order_confirmation']->transferStock = false;
|
||||
BillTypeMapper::create($billType['order_confirmation']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['order_confirmation']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['delivery_note'] = new BillType('Delivery Note');
|
||||
$billType['delivery_note']->transferType = BillTransferType::SALES;
|
||||
$billType['delivery_note']->transferStock = true;
|
||||
BillTypeMapper::create($billType['delivery_note']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['delivery_note']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['invoice'] = new BillType('Invoice');
|
||||
$billType['invoice']->transferType = BillTransferType::SALES;
|
||||
$billType['invoice']->transferStock = false;
|
||||
BillTypeMapper::create($billType['invoice']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['invoice']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['credit_note'] = new BillType('Credit Note');
|
||||
$billType['credit_note']->transferType = BillTransferType::SALES;
|
||||
$billType['credit_note']->transferStock = false;
|
||||
BillTypeMapper::create($billType['credit_note']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['credit_note']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['reverse_invoice'] = new BillType('Credit Note');
|
||||
$billType['reverse_invoice']->transferType = BillTransferType::SALES;
|
||||
$billType['reverse_invoice']->transferStock = false;
|
||||
BillTypeMapper::create($billType['reverse_invoice']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['reverse_invoice']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
||||
|
||||
return $billType;
|
||||
}
|
||||
|
|
@ -119,38 +123,38 @@ final class Installer extends InstallerAbstract
|
|||
$billType['offer'] = new BillType('Offer');
|
||||
$billType['offer']->transferType = BillTransferType::PURCHASE;
|
||||
$billType['offer']->transferStock = false;
|
||||
BillTypeMapper::create($billType['offer']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['offer']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['order_confirmation'] = new BillType('Order Confirmation');
|
||||
$billType['order_confirmation']->transferType = BillTransferType::PURCHASE;
|
||||
$billType['order_confirmation']->transferStock = false;
|
||||
BillTypeMapper::create($billType['order_confirmation']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['order_confirmation']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['delivery_note'] = new BillType('Delivery Note');
|
||||
$billType['delivery_note']->transferType = BillTransferType::PURCHASE;
|
||||
$billType['delivery_note']->transferStock = true;
|
||||
BillTypeMapper::create($billType['delivery_note']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['delivery_note']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['invoice'] = new BillType('Invoice');
|
||||
$billType['invoice']->transferType = BillTransferType::PURCHASE;
|
||||
$billType['invoice']->transferStock = false;
|
||||
BillTypeMapper::create($billType['invoice']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['invoice']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['credit_note'] = new BillType('Credit Note');
|
||||
$billType['credit_note']->transferType = BillTransferType::PURCHASE;
|
||||
$billType['credit_note']->transferStock = false;
|
||||
BillTypeMapper::create($billType['credit_note']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['credit_note']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE));
|
||||
|
||||
$billType['reverse_invoice'] = new BillType('Credit Note');
|
||||
$billType['reverse_invoice']->transferType = BillTransferType::PURCHASE;
|
||||
$billType['reverse_invoice']->transferStock = false;
|
||||
BillTypeMapper::create($billType['reverse_invoice']);
|
||||
BillTypeL11nMapper::create(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
||||
BillTypeMapper::create()->execute($billType['reverse_invoice']);
|
||||
BillTypeL11nMapper::create()->execute(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
|
||||
|
||||
return $billType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Modules\Billing\Models\BillElement;
|
|||
use Modules\Billing\Models\BillElementMapper;
|
||||
use Modules\Billing\Models\BillMapper;
|
||||
use Modules\Billing\Models\NullBillType;
|
||||
use Modules\Billing\Models\SettingsEnum;
|
||||
use Modules\ClientManagement\Models\ClientMapper;
|
||||
use Modules\ItemManagement\Models\ItemMapper;
|
||||
use Modules\Media\Models\CollectionMapper;
|
||||
|
|
@ -91,9 +92,19 @@ final class ApiController extends Controller
|
|||
{
|
||||
$account = 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) {
|
||||
$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 */
|
||||
|
|
@ -225,7 +236,7 @@ final class ApiController extends Controller
|
|||
$element = $this->createBillElementFromRequest($request, $response, $data);
|
||||
$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);
|
||||
$this->updateModel($request->header->account, $old, $new, BillMapper::class, 'bill_element', $request->getOrigin());
|
||||
|
||||
|
|
@ -254,7 +265,7 @@ final class ApiController extends Controller
|
|||
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->itemName = $item->getL11n('name1')->description;
|
||||
$element->quantity = $request->getData('quantity', 'int');
|
||||
|
|
@ -334,10 +345,14 @@ final class ApiController extends Controller
|
|||
{
|
||||
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);
|
||||
$template = CollectionMapper::get((int) $defaultTemplate->content);
|
||||
// @todo: change once bill types have media files/templates assigned
|
||||
$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/'
|
||||
. $bill->createdAt->format('Y') . '/'
|
||||
|
|
|
|||
|
|
@ -14,12 +14,14 @@ 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;
|
||||
use phpOMS\Asset\AssetType;
|
||||
use phpOMS\Contract\RenderableInterface;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
use phpOMS\Localization\ISO3166CharEnum;
|
||||
use phpOMS\Localization\ISO3166NameEnum;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
|
|
@ -57,18 +59,15 @@ final class BackendController extends Controller
|
|||
|
||||
if ($request->getData('ptype') === 'p') {
|
||||
$view->setData('bills',
|
||||
SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getSalesBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
||||
SalesBillMapper::getAll()->with('client')->where('id', (int) ($request->getData('id') ?? 0), '<')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
|
||||
);
|
||||
} elseif ($request->getData('ptype') === 'n') {
|
||||
$view->setData('bills',
|
||||
SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getSalesAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
||||
SalesBillMapper::getAll()->with('client')->where('id', (int) ($request->getData('id') ?? 0), '>')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
|
||||
);
|
||||
} else {
|
||||
$view->setData('bills',
|
||||
SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getSalesAfterPivot(0, limit: 25, depth: 3)
|
||||
SalesBillMapper::getAll()->with('client')->where('id', 0, '>')->where('client', null, '!=')->sort('id', OrderType::DESC)->limit(25)->execute()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +92,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Billing/Theme/Backend/sales-bill');
|
||||
$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);
|
||||
|
||||
|
|
@ -183,18 +182,15 @@ final class BackendController extends Controller
|
|||
|
||||
if ($request->getData('ptype') === 'p') {
|
||||
$view->setData('bills',
|
||||
PurchaseBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getPurchaseBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
||||
PurchaseBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute()
|
||||
);
|
||||
} elseif ($request->getData('ptype') === 'n') {
|
||||
$view->setData('bills',
|
||||
PurchaseBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getPurchaseAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
||||
PurchaseBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute()
|
||||
);
|
||||
} else {
|
||||
$view->setData('bills',
|
||||
PurchaseBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getPurchaseAfterPivot(0, limit: 25, depth: 3)
|
||||
PurchaseBillMapper::getAll()->where('id', 0, '>')->limit(25)->execute()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +215,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Billing/Theme/Backend/purchase-bill');
|
||||
$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);
|
||||
|
||||
|
|
@ -246,18 +242,15 @@ final class BackendController extends Controller
|
|||
|
||||
if ($request->getData('ptype') === 'p') {
|
||||
$view->setData('bills',
|
||||
StockBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getStockBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
||||
StockBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute()
|
||||
);
|
||||
} elseif ($request->getData('ptype') === 'n') {
|
||||
$view->setData('bills',
|
||||
StockBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getStockAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
|
||||
StockBillMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute()
|
||||
);
|
||||
} else {
|
||||
$view->setData('bills',
|
||||
StockBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])
|
||||
::getStockAfterPivot(0, limit: 25, depth: 3)
|
||||
StockBillMapper::getAll()->where('id', 0, '>')->limit(25)->execute()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +275,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Billing/Theme/Backend/purchase-bill');
|
||||
$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);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use Modules\SupplierManagement\Models\Supplier;
|
|||
use phpOMS\Localization\ISO4217CharEnum;
|
||||
use phpOMS\Localization\Money;
|
||||
use Modules\Editor\Models\EditorDoc;
|
||||
use Modules\Media\Models\NullMedia;
|
||||
use Mpdf\Tag\P;
|
||||
|
||||
/**
|
||||
|
|
@ -715,6 +716,27 @@ class Bill implements \JsonSerializable
|
|||
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}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Billing\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class BillElementMapper extends DataMapperAbstract
|
||||
final class BillElementMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @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_order' => ['name' => 'billing_bill_element_order', 'type' => 'int', 'internal' => 'order'],
|
||||
'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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'bill' => [
|
||||
'mapper' => BillMapper::class,
|
||||
'external' => 'billing_bill_element_bill',
|
||||
|
|
@ -82,7 +82,7 @@ final class BillElementMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static string $primaryField = 'billing_bill_element_id';
|
||||
public const PRIMARYFIELD = 'billing_bill_element_id';
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -90,5 +90,5 @@ final class BillElementMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @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\Media\Models\MediaMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use Modules\Editor\Models\EditorDocMapper;
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +29,7 @@ use Modules\Editor\Models\EditorDocMapper;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BillMapper extends DataMapperAbstract
|
||||
class BillMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'billing_bill_id' => ['name' => 'billing_bill_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'billing_bill_number' => ['name' => 'billing_bill_number', 'type' => 'string', 'internal' => 'number'],
|
||||
'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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'elements' => [
|
||||
'mapper' => BillElementMapper::class,
|
||||
'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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'type' => [
|
||||
'mapper' => BillTypeMapper::class,
|
||||
'external' => 'billing_bill_type',
|
||||
|
|
@ -131,7 +131,7 @@ class BillMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'billing_bill_created_by',
|
||||
|
|
@ -152,7 +152,7 @@ class BillMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'billing_bill_id';
|
||||
public const PRIMARYFIELD ='billing_bill_id';
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -160,5 +160,5 @@ class BillMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @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;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Bill type mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class BillTypeL11nMapper extends DataMapperAbstract
|
||||
final class BillTypeL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @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_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'],
|
||||
|
|
@ -45,7 +45,7 @@ final class BillTypeL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'billing_type_l11n';
|
||||
public const TABLE = 'billing_type_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -53,5 +53,5 @@ final class BillTypeL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @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;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Billing mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class BillTypeMapper extends DataMapperAbstract
|
||||
final class BillTypeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'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_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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'l11n' => [
|
||||
'mapper' => BillTypeL11nMapper::class,
|
||||
'table' => 'billing_type_l11n',
|
||||
'self' => 'billing_type_l11n_type',
|
||||
'column' => 'name',
|
||||
'conditional' => true,
|
||||
'external' => null,
|
||||
],
|
||||
];
|
||||
|
|
@ -62,7 +61,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
|||
* @since 1.0.0
|
||||
*/
|
||||
/*
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'owner' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'billing_type_owner',
|
||||
|
|
@ -76,7 +75,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = BillType::class;
|
||||
public const MODEL = BillType::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -84,7 +83,7 @@ final class BillTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'billing_type';
|
||||
public const TABLE = 'billing_type';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -92,5 +91,5 @@ final class BillTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @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 phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\Localization\Defaults\CountryMapper;
|
||||
use phpOMS\Localization\Money;
|
||||
|
||||
|
|
@ -36,7 +35,7 @@ final class PurchaseBillMapper extends BillMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Bill::class;
|
||||
public const MODEL = Bill::class;
|
||||
|
||||
/**
|
||||
* Placeholder
|
||||
|
|
@ -45,15 +44,16 @@ final class PurchaseBillMapper extends BillMapper
|
|||
mixed $pivot,
|
||||
string $column = null,
|
||||
int $limit = 50,
|
||||
int $relations = RelationType::ALL,
|
||||
int $depth = 3,
|
||||
Builder $query = null
|
||||
) : array
|
||||
{
|
||||
$query = self::getQuery(null, [], $relations, $depth);
|
||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::PURCHASE);
|
||||
|
||||
return self::getBeforePivot($pivot, $column, $limit, $relations, $depth, $query);
|
||||
return self::getAll()
|
||||
->with('type')
|
||||
->where('id', $pivot, '<')
|
||||
->where('transferType', BillTransferType::PURCHASE)
|
||||
->limit($limit)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,15 +63,16 @@ final class PurchaseBillMapper extends BillMapper
|
|||
mixed $pivot,
|
||||
string $column = null,
|
||||
int $limit = 50,
|
||||
int $relations = RelationType::ALL,
|
||||
int $depth = 3,
|
||||
Builder $query = null
|
||||
) : array
|
||||
{
|
||||
$query = self::getQuery(null, [], $relations, $depth);
|
||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::PURCHASE);
|
||||
|
||||
return self::getAfterPivot($pivot, $column, $limit, $relations, $depth, $query);
|
||||
return self::getAll()
|
||||
->with('type')
|
||||
->where('id', $pivot, '>')
|
||||
->where('transferType', BillTransferType::PURCHASE)
|
||||
->limit($limit)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,12 +82,12 @@ final class PurchaseBillMapper extends BillMapper
|
|||
{
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('SUM(billing_bill_element_total_netpurchaseprice)')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
|
|
@ -100,10 +101,10 @@ final class PurchaseBillMapper extends BillMapper
|
|||
{
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('SUM(billing_bill_netcosts)')
|
||||
->from(self::$table)
|
||||
->where(self::$table . '.billing_bill_supplier', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->where(self::TABLE . '.billing_bill_supplier', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
|
|
@ -117,12 +118,12 @@ final class PurchaseBillMapper extends BillMapper
|
|||
{
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('SUM(billing_bill_element_single_netpurchaseprice)', 'COUNT(billing_bill_element_total_netpurchaseprice)')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
|
|
@ -137,10 +138,10 @@ final class PurchaseBillMapper extends BillMapper
|
|||
// @todo: only delivers/invoice/production (no offers ...)
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('billing_bill_performance_date')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->orderBy('billing_bill_id', 'DESC')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
|
@ -157,8 +158,8 @@ final class PurchaseBillMapper extends BillMapper
|
|||
// @todo: only delivers/invoice/production (no offers ...)
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('billing_bill_performance_date')
|
||||
->from(self::$table)
|
||||
->where(self::$table . '.billing_bill_supplier', '=', $id)
|
||||
->from(self::TABLE)
|
||||
->where(self::TABLE . '.billing_bill_supplier', '=', $id)
|
||||
->orderBy('billing_bill_id', 'DESC')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
|
@ -188,23 +189,22 @@ final class PurchaseBillMapper extends BillMapper
|
|||
*/
|
||||
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?
|
||||
|
||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
||||
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
||||
$query = self::getQuery();
|
||||
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||
->limit($limit);
|
||||
|
||||
if (!empty(self::$createdAt)) {
|
||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
||||
if (!empty(self::CREATED_AT)) {
|
||||
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||
} 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
|
||||
{
|
||||
$depth = 3;
|
||||
|
||||
// @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->where(self::$table . '_d' . $depth . '.billing_bill_supplier', '=', $id)
|
||||
$query = self::getQuery();
|
||||
$query->where(self::TABLE . '_d1.billing_bill_supplier', '=', $id)
|
||||
->limit($limit);
|
||||
|
||||
if (!empty(self::$createdAt)) {
|
||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
||||
if (!empty(self::CREATED_AT)) {
|
||||
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||
} 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
|
||||
{
|
||||
$depth = 3;
|
||||
|
||||
$query = SupplierMapper::getQuery(null, [], RelationType::ALL, $depth);
|
||||
$query = SupplierMapper::getQuery();
|
||||
$query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
||||
->leftJoin(self::$table, self::$table . '_d' . $depth)
|
||||
->on(SupplierMapper::getTable() . '_d' . $depth . '.suppliermgmt_supplier_id', '=', self::$table . '_d' . $depth . '.billing_bill_supplier')
|
||||
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '<=', $end)
|
||||
->leftJoin(self::TABLE, self::TABLE . '_d1')
|
||||
->on(SupplierMapper::TABLE . '_d1.suppliermgmt_supplier_id', '=', self::TABLE . '_d1.billing_bill_supplier')
|
||||
->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '<=', $end)
|
||||
->orderBy('net_purchase', 'DESC')
|
||||
->limit($limit)
|
||||
->groupBy(SupplierMapper::getTable() . '_d' . $depth . '.suppliermgmt_supplier_id');
|
||||
->groupBy(SupplierMapper::TABLE . '_d1.suppliermgmt_supplier_id');
|
||||
|
||||
$suppliers = SupplierMapper::getAllByQuery($query, RelationType::ALL, $depth);
|
||||
$data = SupplierMapper::getDataLastQuery();
|
||||
$suppliers = SupplierMapper::getAll()->execute($query);
|
||||
$data = SupplierMapper::getRaw()->execute();
|
||||
|
||||
return [$suppliers, $data];
|
||||
}
|
||||
|
|
@ -261,17 +259,17 @@ final class PurchaseBillMapper extends BillMapper
|
|||
public static function getItemRegionPurchase(int $id, \DateTime $start, \DateTime $end) : array
|
||||
{
|
||||
$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')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::getTable() . '.country_region')
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::TABLE . '.country_region')
|
||||
->execute()
|
||||
->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
|
||||
{
|
||||
$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')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::getTable() . '.country_code2')
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::TABLE . '.country_code2')
|
||||
->orderBy('net_purchase', 'DESC')
|
||||
->limit($limit)
|
||||
->execute()
|
||||
|
|
@ -312,12 +310,12 @@ final class PurchaseBillMapper extends BillMapper
|
|||
$result = $query->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_purchase')
|
||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy('year', 'month')
|
||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||
->execute()
|
||||
|
|
@ -335,10 +333,10 @@ final class PurchaseBillMapper extends BillMapper
|
|||
$result = $query->selectAs('SUM(billing_bill_netcosts)', 'net_purchase')
|
||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||
->from(self::$table)
|
||||
->where(self::$table . '.billing_bill_supplier', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->where(self::TABLE . '.billing_bill_supplier', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy('year', 'month')
|
||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||
->execute()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ namespace Modules\Billing\Models;
|
|||
|
||||
use Modules\ClientManagement\Models\ClientMapper;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\Localization\Defaults\CountryMapper;
|
||||
use phpOMS\Localization\Money;
|
||||
|
||||
|
|
@ -36,7 +35,7 @@ final class SalesBillMapper extends BillMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Bill::class;
|
||||
public const MODEL = Bill::class;
|
||||
|
||||
/**
|
||||
* Placeholder
|
||||
|
|
@ -45,15 +44,16 @@ final class SalesBillMapper extends BillMapper
|
|||
mixed $pivot,
|
||||
string $column = null,
|
||||
int $limit = 50,
|
||||
int $relations = RelationType::ALL,
|
||||
int $depth = 3,
|
||||
Builder $query = null
|
||||
) : array
|
||||
{
|
||||
$query = self::getQuery(null, [], $relations, $depth);
|
||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::SALES);
|
||||
|
||||
return self::getBeforePivot($pivot, $column, $limit, $relations, $depth, $query);
|
||||
return self::getAll()
|
||||
->with('type')
|
||||
->where('id', $pivot, '<')
|
||||
->where('transferType', BillTransferType::SALES)
|
||||
->limit($limit)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,15 +63,16 @@ final class SalesBillMapper extends BillMapper
|
|||
mixed $pivot,
|
||||
string $column = null,
|
||||
int $limit = 50,
|
||||
int $relations = RelationType::ALL,
|
||||
int $depth = 3,
|
||||
Builder $query = null
|
||||
) : array
|
||||
{
|
||||
$query = self::getQuery(null, [], $relations, $depth);
|
||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::SALES);
|
||||
|
||||
return self::getAfterPivot($pivot, $column, $limit, $relations, $depth, $query);
|
||||
return self::getAll()
|
||||
->with('type')
|
||||
->where('id', $pivot, '>')
|
||||
->where('transferType', BillTransferType::SALES)
|
||||
->limit($limit)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,12 +82,12 @@ final class SalesBillMapper extends BillMapper
|
|||
{
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('SUM(billing_bill_element_total_netsalesprice)')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
|
|
@ -100,10 +101,10 @@ final class SalesBillMapper extends BillMapper
|
|||
{
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('SUM(billing_bill_netsales)')
|
||||
->from(self::$table)
|
||||
->where(self::$table . '.billing_bill_client', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->where(self::TABLE . '.billing_bill_client', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
|
|
@ -117,12 +118,12 @@ final class SalesBillMapper extends BillMapper
|
|||
{
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('SUM(billing_bill_element_single_netsalesprice)', 'COUNT(billing_bill_element_total_netsalesprice)')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->execute()
|
||||
->fetch();
|
||||
|
||||
|
|
@ -137,10 +138,10 @@ final class SalesBillMapper extends BillMapper
|
|||
// @todo: only delivers/invoice/production (no offers ...)
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('billing_bill_performance_date')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->orderBy('billing_bill_id', 'DESC')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
|
@ -157,8 +158,8 @@ final class SalesBillMapper extends BillMapper
|
|||
// @todo: only delivers/invoice/production (no offers ...)
|
||||
$query = new Builder(self::$db);
|
||||
$result = $query->select('billing_bill_performance_date')
|
||||
->from(self::$table)
|
||||
->where(self::$table . '.billing_bill_client', '=', $id)
|
||||
->from(self::TABLE)
|
||||
->where(self::TABLE . '.billing_bill_client', '=', $id)
|
||||
->orderBy('billing_bill_id', 'DESC')
|
||||
->limit(1)
|
||||
->execute()
|
||||
|
|
@ -188,23 +189,22 @@ final class SalesBillMapper extends BillMapper
|
|||
*/
|
||||
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?
|
||||
|
||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
||||
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
||||
$query = self::getQuery();
|
||||
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||
->limit($limit);
|
||||
|
||||
if (!empty(self::$createdAt)) {
|
||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
||||
if (!empty(self::CREATED_AT)) {
|
||||
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||
} 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
|
||||
{
|
||||
$depth = 3;
|
||||
|
||||
// @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->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $id)
|
||||
$query = self::getQuery();
|
||||
$query->where(self::TABLE . '_d1.billing_bill_client', '=', $id)
|
||||
->limit($limit);
|
||||
|
||||
if (!empty(self::$createdAt)) {
|
||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
||||
if (!empty(self::CREATED_AT)) {
|
||||
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||
} 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
|
||||
{
|
||||
$depth = 3;
|
||||
|
||||
$query = ClientMapper::getQuery(null, [], RelationType::ALL, $depth);
|
||||
$query = ClientMapper::getQuery();
|
||||
$query->selectAs('SUM(billing_bill_element_total_netsalesprice)', 'net_sales')
|
||||
->leftJoin(self::$table, self::$table . '_d' . $depth)
|
||||
->on(ClientMapper::getTable() . '_d' . $depth . '.clientmgmt_client_id', '=', self::$table . '_d' . $depth . '.billing_bill_client')
|
||||
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '_d' . $depth . '.billing_bill_performance_date', '<=', $end)
|
||||
->leftJoin(self::TABLE, self::TABLE . '_d1')
|
||||
->on(ClientMapper::TABLE . '_d1.clientmgmt_client_id', '=', self::TABLE . '_d1.billing_bill_client')
|
||||
->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '_d1.billing_bill_performance_date', '<=', $end)
|
||||
->orderBy('net_sales', 'DESC')
|
||||
->limit($limit)
|
||||
->groupBy(ClientMapper::getTable() . '_d' . $depth . '.clientmgmt_client_id');
|
||||
->groupBy(ClientMapper::TABLE . '_d1.clientmgmt_client_id');
|
||||
|
||||
$clients = ClientMapper::getAllByQuery($query, RelationType::ALL, $depth);
|
||||
$data = ClientMapper::getDataLastQuery();
|
||||
$clients = ClientMapper::getAll()->execute($query);
|
||||
$data = ClientMapper::getRaw()->execute();
|
||||
|
||||
return [$clients, $data];
|
||||
}
|
||||
|
|
@ -260,23 +258,22 @@ final class SalesBillMapper extends BillMapper
|
|||
*/
|
||||
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?
|
||||
|
||||
$query = self::getQuery(null, [], RelationType::ALL, $depth);
|
||||
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_d' . $depth)
|
||||
->on(self::$table . '_d' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_item', '=', $id)
|
||||
$query = self::getQuery();
|
||||
$query->leftJoin(BillElementMapper::TABLE, BillElementMapper::TABLE . '_d1')
|
||||
->on(self::TABLE . '_d1.billing_bill_id', '=', BillElementMapper::TABLE . '_d1.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '_d1.billing_bill_element_item', '=', $id)
|
||||
->limit($limit = 10);
|
||||
|
||||
if (!empty(self::$createdAt)) {
|
||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
||||
if (!empty(self::CREATED_AT)) {
|
||||
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||
} 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
|
||||
{
|
||||
$depth = 3;
|
||||
|
||||
// @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->leftJoin(self::$table, self::$table . '_d' . $depth)
|
||||
->on(BillElementMapper::getTable() . '_d' . $depth . '.billing_bill_element_bill', '=', self::$table . '_d' . $depth . '.billing_bill_id')
|
||||
->where(self::$table . '_d' . $depth . '.billing_bill_client', '=', $client)
|
||||
$query = BillElementMapper::getQuery();
|
||||
$query->leftJoin(self::TABLE, self::TABLE . '_d1')
|
||||
->on(BillElementMapper::TABLE . '_d1.billing_bill_element_bill', '=', self::TABLE . '_d1.billing_bill_id')
|
||||
->where(self::TABLE . '_d1.billing_bill_client', '=', $client)
|
||||
->limit($limit = 10);
|
||||
|
||||
if (!empty(self::$createdAt)) {
|
||||
$query->orderBy(self::$table . '_d' . $depth . '.' . self::$columns[self::$createdAt]['name'], 'DESC');
|
||||
if (!empty(self::CREATED_AT)) {
|
||||
$query->orderBy(self::TABLE . '_d1.' . self::COLUMNS[self::CREATED_AT]['name'], 'DESC');
|
||||
} 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
|
||||
{
|
||||
$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')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::getTable() . '.country_region')
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::TABLE . '.country_region')
|
||||
->execute()
|
||||
->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
|
||||
{
|
||||
$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')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::getTable() . '.country_code2')
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->leftJoin(CountryMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_billCountry', '=', CountryMapper::TABLE . '.country_code2')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy(CountryMapper::TABLE . '.country_code2')
|
||||
->orderBy('net_sales', 'DESC')
|
||||
->limit($limit)
|
||||
->execute()
|
||||
|
|
@ -361,12 +357,12 @@ final class SalesBillMapper extends BillMapper
|
|||
->selectAs('SUM(billing_bill_element_total_netpurchaseprice)', 'net_costs')
|
||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||
->from(self::$table)
|
||||
->leftJoin(BillElementMapper::getTable())
|
||||
->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->leftJoin(BillElementMapper::TABLE)
|
||||
->on(self::TABLE . '.billing_bill_id', '=', BillElementMapper::TABLE . '.billing_bill_element_bill')
|
||||
->where(BillElementMapper::TABLE . '.billing_bill_element_item', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy('year', 'month')
|
||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||
->execute()
|
||||
|
|
@ -385,10 +381,10 @@ final class SalesBillMapper extends BillMapper
|
|||
->selectAs('SUM(billing_bill_netcosts)', 'net_costs')
|
||||
->selectAs('YEAR(billing_bill_performance_date)', 'year')
|
||||
->selectAs('MONTH(billing_bill_performance_date)', 'month')
|
||||
->from(self::$table)
|
||||
->where(self::$table . '.billing_bill_client', '=', $id)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
|
||||
->from(self::TABLE)
|
||||
->where(self::TABLE . '.billing_bill_client', '=', $id)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '>=', $start)
|
||||
->andWhere(self::TABLE . '.billing_bill_performance_date', '<=', $end)
|
||||
->groupBy('year', 'month')
|
||||
->orderBy(['year', 'month'], ['ASC', 'ASC'])
|
||||
->execute()
|
||||
|
|
|
|||
|
|
@ -26,5 +26,5 @@ use phpOMS\Stdlib\Base\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;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -33,7 +32,7 @@ final class StockBillMapper extends BillMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Bill::class;
|
||||
public const MODEL = Bill::class;
|
||||
|
||||
/**
|
||||
* Placeholder
|
||||
|
|
@ -42,15 +41,16 @@ final class StockBillMapper extends BillMapper
|
|||
mixed $pivot,
|
||||
string $column = null,
|
||||
int $limit = 50,
|
||||
int $relations = RelationType::ALL,
|
||||
int $depth = 3,
|
||||
Builder $query = null
|
||||
) : array
|
||||
{
|
||||
$query = self::getQuery(null, [], $relations, $depth);
|
||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::STOCK);
|
||||
|
||||
return self::getBeforePivot($pivot, $column, $limit, $relations, $depth, $query);
|
||||
return self::getAll()
|
||||
->with('type')
|
||||
->where('id', $pivot, '<')
|
||||
->where('transferType', BillTransferType::SALES)
|
||||
->limit($limit)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,14 +60,15 @@ final class StockBillMapper extends BillMapper
|
|||
mixed $pivot,
|
||||
string $column = null,
|
||||
int $limit = 50,
|
||||
int $relations = RelationType::ALL,
|
||||
int $depth = 3,
|
||||
Builder $query = null
|
||||
) : array
|
||||
{
|
||||
$query = self::getQuery(null, [], $relations, $depth);
|
||||
$query->where(BillTypeMapper::getTable() . '_d' . ($depth - 1) . '.billing_type_transfer_type', '=', BillTransferType::STOCK);
|
||||
|
||||
return self::getAfterPivot($pivot, $column, $limit, $relations, $depth, $query);
|
||||
return self::getAll()
|
||||
->with('type')
|
||||
->where('id', $pivot, '>')
|
||||
->where('transferType', BillTransferType::SALES)
|
||||
->limit($limit)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ use phpOMS\Uri\UriFactory;
|
|||
/**
|
||||
* @var \phpOMS\Views\View $this
|
||||
*/
|
||||
|
||||
/** @var Modules\Billing\Models\Bill $bill */
|
||||
$bill = $this->getData('bill');
|
||||
$elements = $bill->getElements();
|
||||
|
||||
$billPdf = $bill->getMediaByType('bill');
|
||||
$billPdf = $bill->getFileByType(0);
|
||||
|
||||
echo $this->getData('nav')->render(); ?>
|
||||
|
||||
|
|
@ -179,9 +179,9 @@ echo $this->getData('nav')->render(); ?>
|
|||
</table>
|
||||
<div class="portlet-foot">
|
||||
<?= $this->getHtml('Freightage'); ?>: 0.00 -
|
||||
<?= $this->getHtml('Net'); ?>: <?= $bill->net->getCurrency(); ?> -
|
||||
<?= $this->getHtml('Net'); ?>: <?= $bill->netSales->getCurrency(); ?> -
|
||||
<?= $this->getHtml('Tax'); ?>: 0.00 -
|
||||
<?= $this->getHtml('Total'); ?>: <?= $bill->gross->getCurrency(); ?>
|
||||
<?= $this->getHtml('Total'); ?>: <?= $bill->grossSales->getCurrency(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
require_once __DIR__ . '/Autoloader.php';
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
$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('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||
|
||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||
|
||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user