mode changes

This commit is contained in:
Dennis Eichhorn 2021-02-20 10:59:06 +01:00
parent b731522bcd
commit 15923d8a3e
46 changed files with 661 additions and 282 deletions

0
.directory Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

3
Admin/Install/Media.install.json Normal file → Executable file
View File

@ -1,18 +1,21 @@
[ [
{ {
"type": "collection", "type": "collection",
"create_directory": true,
"name": "Billing", "name": "Billing",
"virtualPath": "/Modules", "virtualPath": "/Modules",
"user": 1 "user": 1
}, },
{ {
"type": "collection", "type": "collection",
"create_directory": true,
"name": "Templates", "name": "Templates",
"virtualPath": "/Modules/Billing", "virtualPath": "/Modules/Billing",
"user": 1 "user": 1
}, },
{ {
"type": "collection", "type": "collection",
"create_directory": true,
"name": "Bills", "name": "Bills",
"virtualPath": "/Modules/Billing", "virtualPath": "/Modules/Billing",
"user": 1 "user": 1

6
Admin/Install/Media.php Normal file → Executable file
View File

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Modules\Billing\Admin\Install; namespace Modules\Billing\Admin\Install;
use Model\CoreSettings;
use Model\Setting; use Model\Setting;
use Model\SettingMapper;
use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\DatabasePool;
/** /**
@ -42,9 +42,9 @@ class Media
{ {
$media = \Modules\Media\Admin\Installer::installExternal($dbPool, ['path' => __DIR__ . '/Media.install.json']); $media = \Modules\Media\Admin\Installer::installExternal($dbPool, ['path' => __DIR__ . '/Media.install.json']);
$defaultTemplate = \reset($result['upload']); $defaultTemplate = \reset($media['upload'][0]);
$setting = new Setting(); $setting = new Setting();
SettingMapper::create($setting->with(0, 'default_template', (string) $defaulTemplate->getId(), 'Billing')); SettingMapper::create($setting->with(0, 'default_template', (string) $defaultTemplate->getId(), 'Billing'));
} }
} }

2
Admin/Install/Media/bill.pdf.php Normal file → Executable file
View File

@ -284,4 +284,4 @@ mpdf-->
</html> </html>
'); ');
$mpdf->Output(); $mpdf->Output($this->getData('path'), \Mpdf\Output\Destination::FILE);

0
Admin/Install/Navigation.install.json Normal file → Executable file
View File

0
Admin/Install/Navigation.php Normal file → Executable file
View File

View File

@ -0,0 +1,67 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Billing\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Billing\Admin\Install;
use phpOMS\Autoloader;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\Schema\Builder;
/**
* WarehouseManagement class.
*
* @package Modules\Billing\Admin\Install
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class WarehouseManagement
{
/**
* Install comment relation
*
* @param string $path Module path
* @param DatabasePool $dbPool Database pool for database interaction
*
* @return void
*
* @since 1.0.0
*/
public static function install(string $path, DatabasePool $dbPool) : void
{
$builder = new Builder($dbPool->get('schema'));
$builder->alterTable('billing_bill')
->addConstraint('billing_bill_stock_from', 'warehousemgmt_stocklocation', 'warehousemgmt_stocklocation_id')
->execute();
$builder = new Builder($dbPool->get('schema'));
$builder->alterTable('billing_bill')
->addConstraint('billing_bill_stock_to', 'warehousemgmt_stocklocation', 'warehousemgmt_stocklocation_id')
->execute();
$mapper = \file_get_contents(__DIR__ . '/../../Models/BillMapper.php');
if ($mapper === false) {
throw new \Exception('Couldn\'t parse mapper');
}
$mapper = \str_replace([
'// @Module WarehouseManagement ',
'/* @Module WarehouseManagement ',
' @Module WarehouseManagement */',
], '', $mapper);
\file_put_contents(__DIR__ . '/../../Models/BillMapper.php', $mapper);
Autoloader::invalidate(__DIR__ . '/../../Models/BillMapper.php');
}
}

319
Admin/Install/db.json Normal file → Executable file
View File

@ -8,6 +8,18 @@
"null": false, "null": false,
"primary": true, "primary": true,
"autoincrement": true "autoincrement": true
},
"billing_type_transfer_type": {
"description": "What kind of bill is it?",
"name": "billing_type_transfer_type",
"type": "TINYINT",
"null": false
},
"billing_type_transfer_stock": {
"description": "Does this bill type move stock?",
"name": "billing_type_transfer_stock",
"type": "TINYINT(1)",
"null": false
} }
} }
}, },
@ -43,205 +55,226 @@
} }
} }
}, },
"billing_out": { "billing_bill": {
"name": "billing_out", "name": "billing_bill",
"fields": { "fields": {
"billing_out_id": { "billing_bill_id": {
"name": "billing_out_id", "name": "billing_bill_id",
"type": "INT", "type": "INT",
"null": false, "null": false,
"primary": true, "primary": true,
"autoincrement": true "autoincrement": true
}, },
"billing_out_number": { "billing_bill_number": {
"name": "billing_out_number", "name": "billing_bill_number",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"billing_out_info": { "billing_bill_info": {
"name": "billing_out_info", "name": "billing_bill_info",
"type": "TEXT", "type": "TEXT",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_status": { "billing_bill_status": {
"name": "billing_out_status", "name": "billing_bill_status",
"type": "TINYINT", "type": "TINYINT",
"null": false "null": false
}, },
"billing_out_type": { "billing_bill_type": {
"name": "billing_out_type", "name": "billing_bill_type",
"type": "INT", "type": "INT",
"null": false, "null": false,
"foreignTable": "billing_type", "foreignTable": "billing_type",
"foreignKey": "billing_type_id" "foreignKey": "billing_type_id"
}, },
"billing_out_client": { "billing_bill_supplier": {
"name": "billing_out_client", "name": "billing_bill_supplier",
"type": "INT", "type": "INT",
"null": false, "null": true,
"default": null,
"foreignTable": "suppliermgmt_supplier",
"foreignKey": "suppliermgmt_supplier_id"
},
"billing_bill_client": {
"name": "billing_bill_client",
"type": "INT",
"null": true,
"default": null,
"foreignTable": "clientmgmt_client", "foreignTable": "clientmgmt_client",
"foreignKey": "clientmgmt_client_id" "foreignKey": "clientmgmt_client_id"
}, },
"billing_out_shipTo": { "billing_bill_stock_from": {
"name": "billing_out_shipTo", "name": "billing_bill_stock_from",
"type": "INT",
"null": true,
"default": null
},
"billing_bill_stock_to": {
"name": "billing_bill_stock_to",
"type": "INT",
"null": true,
"default": null
},
"billing_bill_shipTo": {
"name": "billing_bill_shipTo",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"billing_out_shipFAO": { "billing_bill_shipFAO": {
"name": "billing_out_shipFAO", "name": "billing_bill_shipFAO",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_shipAddr": { "billing_bill_shipAddr": {
"name": "billing_out_shipAddr", "name": "billing_bill_shipAddr",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_shipCity": { "billing_bill_shipCity": {
"name": "billing_out_shipCity", "name": "billing_bill_shipCity",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_shipZip": { "billing_bill_shipZip": {
"name": "billing_out_shipZip", "name": "billing_bill_shipZip",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_shipCountry": { "billing_bill_shipCountry": {
"name": "billing_out_shipCountry", "name": "billing_bill_shipCountry",
"type": "VARCHAR(3)", "type": "VARCHAR(3)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_billTo": { "billing_bill_billTo": {
"name": "billing_out_billTo", "name": "billing_bill_billTo",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"billing_out_billFAO": { "billing_bill_billFAO": {
"name": "billing_out_billFAO", "name": "billing_bill_billFAO",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_billAddr": { "billing_bill_billAddr": {
"name": "billing_out_billAddr", "name": "billing_bill_billAddr",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_billCity": { "billing_bill_billCity": {
"name": "billing_out_billCity", "name": "billing_bill_billCity",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_billZip": { "billing_bill_billZip": {
"name": "billing_out_billZip", "name": "billing_bill_billZip",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_billCountry": { "billing_bill_billCountry": {
"name": "billing_out_billCountry", "name": "billing_bill_billCountry",
"type": "VARCHAR(3)", "type": "VARCHAR(3)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_created_at": { "billing_bill_created_at": {
"name": "billing_out_created_at", "name": "billing_bill_created_at",
"type": "DATETIME", "type": "DATETIME",
"null": false "null": false
}, },
"billing_out_performance_date": { "billing_bill_performance_date": {
"name": "billing_out_performance_date", "name": "billing_bill_performance_date",
"type": "DATETIME", "type": "DATETIME",
"null": false "null": false
}, },
"billing_out_created_by": { "billing_bill_created_by": {
"name": "billing_out_created_by", "name": "billing_bill_created_by",
"type": "INT", "type": "INT",
"null": false, "null": false,
"foreignTable": "account", "foreignTable": "account",
"foreignKey": "account_id" "foreignKey": "account_id"
}, },
"billing_out_gross": { "billing_bill_gross": {
"name": "billing_out_gross", "name": "billing_bill_gross",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_net": { "billing_bill_net": {
"name": "billing_out_net", "name": "billing_bill_net",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_costs": { "billing_bill_costs": {
"name": "billing_out_costs", "name": "billing_bill_costs",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_profit": { "billing_bill_profit": {
"name": "billing_out_profit", "name": "billing_bill_profit",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_currency": { "billing_bill_currency": {
"name": "billing_out_currency", "name": "billing_bill_currency",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_referral": { "billing_bill_referral": {
"name": "billing_out_referral", "name": "billing_bill_referral",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null, "default": null,
"foreignTable": "account", "foreignTable": "account",
"foreignKey": "account_id" "foreignKey": "account_id"
}, },
"billing_out_referral_name": { "billing_bill_referral_name": {
"name": "billing_out_referral_name", "name": "billing_bill_referral_name",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_reference": { "billing_bill_reference": {
"name": "billing_out_reference", "name": "billing_bill_reference",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_payment": { "billing_bill_payment": {
"name": "billing_out_payment", "name": "billing_bill_payment",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_payment_text": { "billing_bill_payment_text": {
"name": "billing_out_payment_text", "name": "billing_bill_payment_text",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_paymentterms": { "billing_bill_paymentterms": {
"name": "billing_out_paymentterms", "name": "billing_bill_paymentterms",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_paymentterms_text": { "billing_bill_paymentterms_text": {
"name": "billing_out_paymentterms_text", "name": "billing_bill_paymentterms_text",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_ship_type": { "billing_bill_ship_type": {
"name": "billing_out_ship_type", "name": "billing_bill_ship_type",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_ship_text": { "billing_bill_ship_text": {
"name": "billing_bill_ship_text", "name": "billing_bill_ship_text",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"default": null, "default": null,
@ -249,168 +282,194 @@
} }
} }
}, },
"billing_out_element": { "billing_bill_element": {
"name": "billing_out_element", "name": "billing_bill_element",
"fields": { "fields": {
"billing_out_element_id": { "billing_bill_element_id": {
"name": "billing_out_element_id", "name": "billing_bill_element_id",
"type": "INT", "type": "INT",
"null": false, "null": false,
"primary": true, "primary": true,
"autoincrement": true "autoincrement": true
}, },
"billing_out_element_order": { "billing_bill_element_order": {
"name": "billing_out_element_order", "name": "billing_bill_element_order",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_element_item": { "billing_bill_element_item": {
"name": "billing_out_element_item", "name": "billing_bill_element_item",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_item_segment": { "billing_bill_element_item_segment": {
"name": "billing_out_element_item_segment", "name": "billing_bill_element_item_segment",
"type": "INT", "type": "INT",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_element_item_number": { "billing_bill_element_item_number": {
"name": "billing_out_element_item_number", "name": "billing_bill_element_item_number",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"billing_out_element_item_name": { "billing_bill_element_item_name": {
"name": "billing_out_element_item_name", "name": "billing_bill_element_item_name",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"billing_out_element_item_desc": { "billing_bill_element_item_desc": {
"name": "billing_out_element_item_desc", "name": "billing_bill_element_item_desc",
"type": "VARCHAR(255)", "type": "VARCHAR(255)",
"null": false "null": false
}, },
"billing_out_element_quantity": { "billing_bill_element_quantity": {
"name": "billing_out_element_quantity", "name": "billing_bill_element_quantity",
"type": "INT", "type": "INT",
"null": false "null": false
}, },
"billing_out_element_single_salesprice_net": { "billing_bill_element_single_salesprice_net": {
"name": "billing_out_element_single_salesprice_net", "name": "billing_bill_element_single_salesprice_net",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_single_purchaseprice_net": { "billing_bill_element_single_purchaseprice_net": {
"name": "billing_out_element_single_purchaseprice_net", "name": "billing_bill_element_single_purchaseprice_net",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_total_salesprice_net": { "billing_bill_element_total_salesprice_net": {
"name": "billing_out_element_total_salesprice_net", "name": "billing_bill_element_total_salesprice_net",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_total_purchaseprice_net": { "billing_bill_element_total_purchaseprice_net": {
"name": "billing_out_element_total_purchaseprice_net", "name": "billing_bill_element_total_purchaseprice_net",
"type": "BIGINT", "type": "BIGINT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_price_discount_single": { "billing_bill_element_price_discount_single": {
"name": "billing_out_element_price_discount_single", "name": "billing_bill_element_price_discount_single",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_price_discount_total": { "billing_bill_element_price_discount_total": {
"name": "billing_out_element_price_discount_total", "name": "billing_bill_element_price_discount_total",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_percentage_discount_single": { "billing_bill_element_percentage_discount_single": {
"name": "billing_out_element_percentage_discount_single", "name": "billing_bill_element_percentage_discount_single",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_percentage_discount_total": { "billing_bill_element_percentage_discount_total": {
"name": "billing_out_element_percentage_discount_total", "name": "billing_bill_element_percentage_discount_total",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_quantity_discount": { "billing_bill_element_quantity_discount": {
"name": "billing_out_element_quantity_discount", "name": "billing_bill_element_quantity_discount",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_price_single_net": { "billing_bill_element_price_single_net": {
"name": "billing_out_element_price_single_net", "name": "billing_bill_element_price_single_net",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_price_total_net": { "billing_bill_element_price_total_net": {
"name": "billing_out_element_price_total_net", "name": "billing_bill_element_price_total_net",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_tax_price": { "billing_bill_element_tax_price": {
"name": "billing_out_element_tax_price", "name": "billing_bill_element_tax_price",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_tax_type": { "billing_bill_element_tax_type": {
"name": "billing_out_element_tax_type", "name": "billing_bill_element_tax_type",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_tax_percentage": { "billing_bill_element_tax_percentage": {
"name": "billing_out_element_tax_percentage", "name": "billing_bill_element_tax_percentage",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_price_single_gross": { "billing_bill_element_price_single_gross": {
"name": "billing_out_element_price_single_gross", "name": "billing_bill_element_price_single_gross",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_price_total_gross": { "billing_bill_element_price_total_gross": {
"name": "billing_out_element_price_total_gross", "name": "billing_bill_element_price_total_gross",
"type": "INT", "type": "INT",
"null": true, "null": true,
"default": null "default": null
}, },
"billing_out_element_bill": { "billing_bill_element_bill": {
"name": "billing_out_element_bill", "name": "billing_bill_element_bill",
"type": "INT", "type": "INT",
"null": false, "null": false,
"foreignTable": "billing_out", "foreignTable": "billing_bill",
"foreignKey": "billing_out_id" "foreignKey": "billing_bill_id"
}, },
"billing_out_element_promotion": { "billing_bill_element_promotion": {
"name": "billing_out_element_promotion", "name": "billing_bill_element_promotion",
"type": "INT", "type": "INT",
"default": null, "default": null,
"null": true "null": true
}, },
"billing_out_element_event": { "billing_bill_element_event": {
"name": "billing_out_element_event", "name": "billing_bill_element_event",
"type": "INT", "type": "INT",
"default": null, "default": null,
"null": true "null": true
} }
} }
},
"billing_bill_media": {
"name": "billing_bill_media",
"fields": {
"billing_bill_media_id": {
"name": "billing_bill_media_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"billing_bill_media_src": {
"name": "billing_bill_media_src",
"type": "INT",
"null": false,
"foreignTable": "billing_bill",
"foreignKey": "billing_bill_id"
},
"billing_bill_media_dst": {
"name": "billing_bill_media_dst",
"type": "INT",
"null": false,
"foreignTable": "media",
"foreignKey": "media_id"
}
}
} }
} }

83
Admin/Installer.php Normal file → Executable file
View File

@ -18,6 +18,7 @@ use Modules\Billing\Models\BillType;
use Modules\Billing\Models\BillTypeL11n; use Modules\Billing\Models\BillTypeL11n;
use Modules\Billing\Models\BillTypeL11nMapper; use Modules\Billing\Models\BillTypeL11nMapper;
use Modules\Billing\Models\BillTypeMapper; use Modules\Billing\Models\BillTypeMapper;
use Modules\Billing\Models\BillTransferType;
use phpOMS\Config\SettingsInterface; use phpOMS\Config\SettingsInterface;
use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Localization\ISO639x1Enum; use phpOMS\Localization\ISO639x1Enum;
@ -41,44 +42,120 @@ final class Installer extends InstallerAbstract
{ {
parent::install($dbPool, $info, $cfgHandler); parent::install($dbPool, $info, $cfgHandler);
self::createBillTypes(); self::createOutgoingBillTypes();
self::createIncomingBillTypes();
self::createTransferBillTypes();
} }
/** /**
* Install default bill types * Install default outgoing bill types
* *
* @return BillType[] * @return BillType[]
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private static function createBillTypes() : array private static function createOutgoingBillTypes() : array
{ {
$billType = []; $billType = [];
$billType['offer'] = new BillType('Offer'); $billType['offer'] = new BillType('Offer');
$billType['offer']->transferType = BillTransferType::SALES;
$billType['offer']->transferStock = false;
BillTypeMapper::create($billType['offer']); BillTypeMapper::create($billType['offer']);
BillTypeL11nMapper::create(new BillTypeL11n($billType['offer']->getId(), 'Angebot', ISO639x1Enum::_DE)); BillTypeL11nMapper::create(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']->transferStock = false;
BillTypeMapper::create($billType['order_confirmation']); BillTypeMapper::create($billType['order_confirmation']);
BillTypeL11nMapper::create(new BillTypeL11n($billType['order_confirmation']->getId(), 'Auftragsbestaetigung', ISO639x1Enum::_DE)); BillTypeL11nMapper::create(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']->transferStock = true;
BillTypeMapper::create($billType['delivery_note']); BillTypeMapper::create($billType['delivery_note']);
BillTypeL11nMapper::create(new BillTypeL11n($billType['delivery_note']->getId(), 'Lieferschein', ISO639x1Enum::_DE)); BillTypeL11nMapper::create(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']->transferStock = false;
BillTypeMapper::create($billType['invoice']); BillTypeMapper::create($billType['invoice']);
BillTypeL11nMapper::create(new BillTypeL11n($billType['invoice']->getId(), 'Rechnung', ISO639x1Enum::_DE)); BillTypeL11nMapper::create(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']->transferStock = false;
BillTypeMapper::create($billType['credit_note']); BillTypeMapper::create($billType['credit_note']);
BillTypeL11nMapper::create(new BillTypeL11n($billType['credit_note']->getId(), 'Rechnungskorrektur', ISO639x1Enum::_DE)); BillTypeL11nMapper::create(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']->transferStock = false;
BillTypeMapper::create($billType['reverse_invoice']); BillTypeMapper::create($billType['reverse_invoice']);
BillTypeL11nMapper::create(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE)); BillTypeL11nMapper::create(new BillTypeL11n($billType['reverse_invoice']->getId(), 'Gutschrift', ISO639x1Enum::_DE));
return $billType; return $billType;
} }
/**
* Install default incoming bill types
*
* @return BillType[]
*
* @since 1.0.0
*/
private static function createIncomingBillTypes() : array
{
$billType = [];
$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));
$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));
$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));
$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));
$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));
$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));
return $billType;
}
/**
* Install default transfer bill types
*
* @return BillType[]
*
* @since 1.0.0
*/
private static function createTransferBillTypes() : array
{
return [];
}
} }

0
Admin/Routes/Web/Backend.php Normal file → Executable file
View File

0
Admin/Status.php Normal file → Executable file
View File

0
Admin/Uninstaller.php Normal file → Executable file
View File

0
Admin/Updater.php Normal file → Executable file
View File

77
Controller/ApiController.php Normal file → Executable file
View File

@ -22,6 +22,7 @@ use Modules\Billing\Models\BillMapper;
use Modules\Billing\Models\NullBillType; use Modules\Billing\Models\NullBillType;
use Modules\ClientManagement\Models\ClientMapper; use Modules\ClientManagement\Models\ClientMapper;
use Modules\ClientManagement\Models\NullClient; use Modules\ClientManagement\Models\NullClient;
use Modules\SupplierManagement\Models\SupplierMapper;
use Modules\ItemManagement\Models\ItemMapper; use Modules\ItemManagement\Models\ItemMapper;
use phpOMS\Localization\Money; use phpOMS\Localization\Money;
use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\Http\RequestStatusCode;
@ -29,6 +30,12 @@ use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract; use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract; use phpOMS\Message\ResponseAbstract;
use phpOMS\Model\Message\FormValidation; use phpOMS\Model\Message\FormValidation;
use Model\CoreSettings;
use Modules\Media\Models\CollectionMapper;
use Modules\Media\Models\UploadStatus;
use phpOMS\Views\View;
use phpOMS\System\MimeType;
use phpOMS\Autoloader;
/** /**
* Billing class. * Billing class.
@ -80,16 +87,23 @@ final class ApiController extends Controller
*/ */
public function createBillFromRequest(RequestAbstract $request, ResponseAbstract $response, $data = null) : Bill public function createBillFromRequest(RequestAbstract $request, ResponseAbstract $response, $data = null) : Bill
{ {
$client = ClientMapper::get((int) $request->getData('client')); if ($request->getData('client') !== null) {
$account = ClientMapper::get((int) $request->getData('client'));
} elseif ($request->getData('supplier') !== null) {
$account = SupplierMapper::get((int) $request->getData('supplier'));
}
$bill = new Bill(); $bill = new Bill();
$bill->setCreatedBy(new NullAccount($request->header->account)); $bill->setCreatedBy(new NullAccount($request->header->account));
$bill->number = '{y}-{id}'; // @todo: use admin defined format $bill->number = '{y}-{id}'; // @todo: use admin defined format
$bill->billTo = $request->getData('billto') $bill->billTo = $request->getData('billto')
?? ($client->profile->account->name1 . (!empty($client->profile->account->name2) ? ', ' . $client->profile->account->name2 : '')); // @todo: use defaultInvoiceAddress or mainAddress. also consider to use billto1, billto2, billto3 (for multiple lines e.g. name2, fao etc.) ?? ($account->profile->account->name1 . (!empty($account->profile->account->name2) ? ', ' . $account->profile->account->name2 : '')); // @todo: use defaultInvoiceAddress or mainAddress. also consider to use billto1, billto2, billto3 (for multiple lines e.g. name2, fao etc.)
$bill->billCountry = $request->getData('billtocountry') ?? $client->mainAddress->getCountry(); $bill->billZip = $request->getData('billtopostal') ?? $account->mainAddress->postal;
$bill->billCity = $request->getData('billtocity') ?? $account->mainAddress->city;
$bill->billCountry = $request->getData('billtocountry') ?? $account->mainAddress->getCountry();
$bill->type = new NullBillType((int) $request->getData('type')); $bill->type = new NullBillType((int) $request->getData('type'));
$bill->client = new NullClient((int) $request->getData('client')); $bill->client = $request->getData('client') === null ? null : $account;
$bill->supplier = $request->getData('supplier') === null ? null : $account;
$bill->performanceDate = new \DateTime($request->getData('performancedate') ?? 'now'); $bill->performanceDate = new \DateTime($request->getData('performancedate') ?? 'now');
return $bill; return $bill;
@ -252,8 +266,52 @@ final class ApiController extends Controller
*/ */
public function apiBillPdfArchiveCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void public function apiBillPdfArchiveCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{ {
$this->apiBillPdfCreate($request, $response, $data); Autoloader::addPath(__DIR__ . '/../../../Resources/');
// upload pdf to media module
$bill = BillMapper::get($request->getData('bill'));
$defaultTemplate = $this->app->appSettings->get(null, 'default_template', self::MODULE_NAME);
$template = CollectionMapper::get((int) $defaultTemplate['content']);
$pdfDir = __DIR__ . '/../../../Modules/Media/Files/Modules/Billing/Bills/'
. $bill->createdAt->format('Y') . '/'
. $bill->createdAt->format('m') . '/'
. $bill->createdAt->format('d') . '/';
if (!\is_dir($pdfDir)) {
\mkdir($pdfDir, 0755, true);
}
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/' . \substr($template->getSourceByName('bill.pdf.php')->getPath(), 0, -8), 'pdf.php');
$view->setData('bill', $bill);
$view->setData('path', $pdfDir . $request->getData('bill') . '.pdf');
$pdf = $view->build();
$media = $this->app->moduleManager->get('Media')->createDbEntry(
[
'status' => UploadStatus::OK,
'name' => $request->getData('bill') . '.pdf',
'path' => $pdfDir,
'filename' => $request->getData('bill') . '.pdf',
'size' => \filesize($pdfDir . $request->getData('bill') . '.pdf'),
'extension' => 'pdf',
],
$request->header->account,
'/Modules/Billing/Bills/'
. $bill->createdAt->format('Y') . '/'
. $bill->createdAt->format('m') . '/'
. $bill->createdAt->format('d'),
'bill'
);
$this->createModelRelation(
$request->header->account,
$bill->getId(),
$media->getId(),
BillMapper::class, 'media', '', $request->getOrigin()
);
} }
/** /**
@ -271,12 +329,5 @@ final class ApiController extends Controller
*/ */
public function apiBillPdfCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void public function apiBillPdfCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{ {
$bill = BillMapper::get($request->getData('id'));
$defaultTemplate = CoreSettings::get(null, 'default_template', self::MODULE_NAME);
$template = CollectionMapper::get((int) $defaultTemplate);
// get default template from database OR get template based on provided request template id
// create pdf based on template
} }
} }

6
Controller/BackendController.php Normal file → Executable file
View File

@ -52,17 +52,17 @@ final class BackendController extends Controller
if ($request->getData('ptype') === 'p') { if ($request->getData('ptype') === 'p') {
$view->setData('bills', $view->setData('bills',
BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class]) BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class])
::getBeforePivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 4) ::getBeforePivot((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',
BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class]) BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class])
::getAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 4) ::getAfterPivot((int) ($request->getData('id') ?? 0), limit: 25, depth: 3)
); );
} else { } else {
$view->setData('bills', $view->setData('bills',
BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class]) BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class])
::getAfterPivot(0, limit: 25, depth: 4) ::getAfterPivot(0, limit: 25, depth: 3)
); );
} }

0
Controller/Controller.php Normal file → Executable file
View File

0
Docs/Dev/en/SUMMARY.md Normal file
View File

0
Docs/Dev/en/structure.md Normal file
View File

69
Models/Bill.php Normal file → Executable file
View File

@ -16,6 +16,7 @@ namespace Modules\Billing\Models;
use Modules\Admin\Models\Account; use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount; use Modules\Admin\Models\NullAccount;
use Modules\Media\Models\Media;
use phpOMS\Localization\ISO4217CharEnum; use phpOMS\Localization\ISO4217CharEnum;
use phpOMS\Localization\Money; use phpOMS\Localization\Money;
@ -51,9 +52,7 @@ class Bill implements \JsonSerializable
* @var int|BillType * @var int|BillType
* @since 1.0.0 * @since 1.0.0
*/ */
public int | public int | BillType $type = 0;
BillType $type = 0;
/** /**
* Bill status. * Bill status.
@ -96,6 +95,7 @@ BillType $type = 0;
public Account $createdBy; public Account $createdBy;
public $client = 0; public $client = 0;
public $supplier = 0;
/** /**
* Receiver. * Receiver.
@ -159,7 +159,7 @@ BillType $type = 0;
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private $billFAO = ''; public string $billFAO = '';
/** /**
* Billing address. * Billing address.
@ -167,7 +167,7 @@ BillType $type = 0;
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private $billAddress = ''; public string $billAddress = '';
/** /**
* Billing city. * Billing city.
@ -175,7 +175,7 @@ BillType $type = 0;
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private $billCity = ''; public string $billCity = '';
/** /**
* Billing zip. * Billing zip.
@ -183,7 +183,7 @@ BillType $type = 0;
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private $billZip = ''; public string $billZip = '';
/** /**
* Billing country. * Billing country.
@ -241,6 +241,14 @@ BillType $type = 0;
*/ */
private int $reference = 0; private int $reference = 0;
/**
* Media files
*
* @var array
* @since 1.0.0
*/
protected array $media = [];
/** /**
* Constructor. * Constructor.
* *
@ -1211,6 +1219,53 @@ BillType $type = 0;
$this->elements[] = $element; $this->elements[] = $element;
} }
/**
* Get all media
*
* @return Media[]
*
* @since 1.0.0
*/
public function getMedia() : array
{
return $this->media;
}
/**
* Add media
*
* @param Media $media Media to add
*
* @return void
*
* @since 1.0.0
*/
public function addMedia(Media $media) : void
{
$this->media[] = $media;
}
/**
* Get media file by type
*
* @param string $type Media type
*
* @return Media
*
* @since 1.0.0
*/
public function getMediaByType(string $type) : Media
{
foreach ($this->media as $media) {
if ($media->type === $type) {
return $media;
}
}
return new NullMedia();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

0
Models/BillElement.php Normal file → Executable file
View File

30
Models/BillElementMapper.php Normal file → Executable file
View File

@ -33,18 +33,18 @@ final class BillElementMapper extends DataMapperAbstract
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ protected static array $columns = [
'billing_out_element_id' => ['name' => 'billing_out_element_id', 'type' => 'int', 'internal' => 'id'], 'billing_bill_element_id' => ['name' => 'billing_bill_element_id', 'type' => 'int', 'internal' => 'id'],
'billing_out_element_order' => ['name' => 'billing_out_element_order', 'type' => 'int', 'internal' => 'order'], 'billing_bill_element_order' => ['name' => 'billing_bill_element_order', 'type' => 'int', 'internal' => 'order'],
'billing_out_element_item' => ['name' => 'billing_out_element_item', 'type' => 'int', 'internal' => 'item'], 'billing_bill_element_item' => ['name' => 'billing_bill_element_item', 'type' => 'int', 'internal' => 'item'],
'billing_out_element_item_number' => ['name' => 'billing_out_element_item_number', 'type' => 'string', 'internal' => 'itemNumber'], 'billing_bill_element_item_number' => ['name' => 'billing_bill_element_item_number', 'type' => 'string', 'internal' => 'itemNumber'],
'billing_out_element_item_name' => ['name' => 'billing_out_element_item_name', 'type' => 'string', 'internal' => 'itemName'], 'billing_bill_element_item_name' => ['name' => 'billing_bill_element_item_name', 'type' => 'string', 'internal' => 'itemName'],
'billing_out_element_item_desc' => ['name' => 'billing_out_element_item_desc', 'type' => 'string', 'internal' => 'itemDescription'], 'billing_bill_element_item_desc' => ['name' => 'billing_bill_element_item_desc', 'type' => 'string', 'internal' => 'itemDescription'],
'billing_out_element_quantity' => ['name' => 'billing_out_element_quantity', 'type' => 'int', 'internal' => 'quantity'], 'billing_bill_element_quantity' => ['name' => 'billing_bill_element_quantity', 'type' => 'int', 'internal' => 'quantity'],
'billing_out_element_single_salesprice_net' => ['name' => 'billing_out_element_single_salesprice_net', 'type' => 'Serializable', 'internal' => 'singleSalesPriceNet'], 'billing_bill_element_single_salesprice_net' => ['name' => 'billing_bill_element_single_salesprice_net', 'type' => 'Serializable', 'internal' => 'singleSalesPriceNet'],
'billing_out_element_single_purchaseprice_net' => ['name' => 'billing_out_element_single_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'singlePurchasePriceNet'], 'billing_bill_element_single_purchaseprice_net' => ['name' => 'billing_bill_element_single_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'singlePurchasePriceNet'],
'billing_out_element_total_salesprice_net' => ['name' => 'billing_out_element_total_salesprice_net', 'type' => 'Serializable', 'internal' => 'totalSalesPriceNet'], 'billing_bill_element_total_salesprice_net' => ['name' => 'billing_bill_element_total_salesprice_net', 'type' => 'Serializable', 'internal' => 'totalSalesPriceNet'],
'billing_out_element_total_purchaseprice_net' => ['name' => 'billing_out_element_total_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'totalPurchasePriceNet'], 'billing_bill_element_total_purchaseprice_net' => ['name' => 'billing_bill_element_total_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'totalPurchasePriceNet'],
'billing_out_element_bill' => ['name' => 'billing_out_element_bill', 'type' => 'int', 'internal' => 'bill'], 'billing_bill_element_bill' => ['name' => 'billing_bill_element_bill', 'type' => 'int', 'internal' => 'bill'],
]; ];
/** /**
@ -56,7 +56,7 @@ final class BillElementMapper extends DataMapperAbstract
protected static array $belongsTo = [ protected static array $belongsTo = [
'bill' => [ 'bill' => [
'mapper' => BillMapper::class, 'mapper' => BillMapper::class,
'external' => 'billing_out_element_bill', 'external' => 'billing_bill_element_bill',
], ],
]; ];
@ -66,7 +66,7 @@ final class BillElementMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public static string $primaryField = 'billing_out_element_id'; public static string $primaryField = 'billing_bill_element_id';
/** /**
* Primary table. * Primary table.
@ -74,5 +74,5 @@ final class BillElementMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public static string $table = 'billing_out_element'; public static string $table = 'billing_bill_element';
} }

213
Models/BillMapper.php Normal file → Executable file
View File

@ -16,6 +16,8 @@ namespace Modules\Billing\Models;
use Modules\Admin\Models\AccountMapper; use Modules\Admin\Models\AccountMapper;
use Modules\ClientManagement\Models\ClientMapper; use Modules\ClientManagement\Models\ClientMapper;
use Modules\SupplierManagement\Models\SupplierMapper;
use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\RelationType; use phpOMS\DataStorage\Database\RelationType;
@ -39,41 +41,42 @@ final class BillMapper extends DataMapperAbstract
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ protected static array $columns = [
'billing_out_id' => ['name' => 'billing_out_id', 'type' => 'int', 'internal' => 'id'], 'billing_bill_id' => ['name' => 'billing_bill_id', 'type' => 'int', 'internal' => 'id'],
'billing_out_number' => ['name' => 'billing_out_number', 'type' => 'string', 'internal' => 'number'], 'billing_bill_number' => ['name' => 'billing_bill_number', 'type' => 'string', 'internal' => 'number'],
'billing_out_type' => ['name' => 'billing_out_type', 'type' => 'int', 'internal' => 'type'], 'billing_bill_type' => ['name' => 'billing_bill_type', 'type' => 'int', 'internal' => 'type'],
'billing_out_info' => ['name' => 'billing_out_info', 'type' => 'string', 'internal' => 'info'], 'billing_bill_info' => ['name' => 'billing_bill_info', 'type' => 'string', 'internal' => 'info'],
'billing_out_status' => ['name' => 'billing_out_status', 'type' => 'int', 'internal' => 'status'], 'billing_bill_status' => ['name' => 'billing_bill_status', 'type' => 'int', 'internal' => 'status'],
'billing_out_shipTo' => ['name' => 'billing_out_shipTo', 'type' => 'string', 'internal' => 'shipTo'], 'billing_bill_shipTo' => ['name' => 'billing_bill_shipTo', 'type' => 'string', 'internal' => 'shipTo'],
'billing_out_shipFAO' => ['name' => 'billing_out_shipFAO', 'type' => 'string', 'internal' => 'shipFAO'], 'billing_bill_shipFAO' => ['name' => 'billing_bill_shipFAO', 'type' => 'string', 'internal' => 'shipFAO'],
'billing_out_shipAddr' => ['name' => 'billing_out_shipAddr', 'type' => 'string', 'internal' => 'shipAddress'], 'billing_bill_shipAddr' => ['name' => 'billing_bill_shipAddr', 'type' => 'string', 'internal' => 'shipAddress'],
'billing_out_shipCity' => ['name' => 'billing_out_shipCity', 'type' => 'string', 'internal' => 'shipCity'], 'billing_bill_shipCity' => ['name' => 'billing_bill_shipCity', 'type' => 'string', 'internal' => 'shipCity'],
'billing_out_shipZip' => ['name' => 'billing_out_shipZip', 'type' => 'string', 'internal' => 'shipZip'], 'billing_bill_shipZip' => ['name' => 'billing_bill_shipZip', 'type' => 'string', 'internal' => 'shipZip'],
'billing_out_shipCountry' => ['name' => 'billing_out_shipCountry', 'type' => 'string', 'internal' => 'shipCountry'], 'billing_bill_shipCountry' => ['name' => 'billing_bill_shipCountry', 'type' => 'string', 'internal' => 'shipCountry'],
'billing_out_billTo' => ['name' => 'billing_out_billTo', 'type' => 'string', 'internal' => 'billTo'], 'billing_bill_billTo' => ['name' => 'billing_bill_billTo', 'type' => 'string', 'internal' => 'billTo'],
'billing_out_billFAO' => ['name' => 'billing_out_billFAO', 'type' => 'string', 'internal' => 'billFAO'], 'billing_bill_billFAO' => ['name' => 'billing_bill_billFAO', 'type' => 'string', 'internal' => 'billFAO'],
'billing_out_billAddr' => ['name' => 'billing_out_billAddr', 'type' => 'string', 'internal' => 'billAddress'], 'billing_bill_billAddr' => ['name' => 'billing_bill_billAddr', 'type' => 'string', 'internal' => 'billAddress'],
'billing_out_billCity' => ['name' => 'billing_out_billCity', 'type' => 'string', 'internal' => 'billCity'], 'billing_bill_billCity' => ['name' => 'billing_bill_billCity', 'type' => 'string', 'internal' => 'billCity'],
'billing_out_billZip' => ['name' => 'billing_out_billZip', 'type' => 'string', 'internal' => 'billZip'], 'billing_bill_billZip' => ['name' => 'billing_bill_billZip', 'type' => 'string', 'internal' => 'billZip'],
'billing_out_billCountry' => ['name' => 'billing_out_billCountry', 'type' => 'string', 'internal' => 'billCountry'], 'billing_bill_billCountry' => ['name' => 'billing_bill_billCountry', 'type' => 'string', 'internal' => 'billCountry'],
'billing_out_gross' => ['name' => 'billing_out_gross', 'type' => 'Serializable', 'internal' => 'gross'], 'billing_bill_gross' => ['name' => 'billing_bill_gross', 'type' => 'Serializable', 'internal' => 'gross'],
'billing_out_net' => ['name' => 'billing_out_net', 'type' => 'Serializable', 'internal' => 'net'], 'billing_bill_net' => ['name' => 'billing_bill_net', 'type' => 'Serializable', 'internal' => 'net'],
'billing_out_costs' => ['name' => 'billing_out_costs', 'type' => 'Serializable', 'internal' => 'costs'], 'billing_bill_costs' => ['name' => 'billing_bill_costs', 'type' => 'Serializable', 'internal' => 'costs'],
'billing_out_profit' => ['name' => 'billing_out_profit', 'type' => 'Serializable', 'internal' => 'profit'], 'billing_bill_profit' => ['name' => 'billing_bill_profit', 'type' => 'Serializable', 'internal' => 'profit'],
'billing_out_currency' => ['name' => 'billing_out_currency', 'type' => 'int', 'internal' => 'currency'], 'billing_bill_currency' => ['name' => 'billing_bill_currency', 'type' => 'int', 'internal' => 'currency'],
'billing_out_referral' => ['name' => 'billing_out_referral', 'type' => 'int', 'internal' => 'referral'], 'billing_bill_referral' => ['name' => 'billing_bill_referral', 'type' => 'int', 'internal' => 'referral'],
'billing_out_referral_name' => ['name' => 'billing_out_referral_name', 'type' => 'string', 'internal' => 'referralName'], 'billing_bill_referral_name' => ['name' => 'billing_bill_referral_name', 'type' => 'string', 'internal' => 'referralName'],
'billing_out_reference' => ['name' => 'billing_out_reference', 'type' => 'int', 'internal' => 'reference'], 'billing_bill_reference' => ['name' => 'billing_bill_reference', 'type' => 'int', 'internal' => 'reference'],
'billing_out_payment' => ['name' => 'billing_out_payment', 'type' => 'int', 'internal' => 'payment'], 'billing_bill_payment' => ['name' => 'billing_bill_payment', 'type' => 'int', 'internal' => 'payment'],
'billing_out_payment_text' => ['name' => 'billing_out_payment_text', 'type' => 'string', 'internal' => 'paymentText'], 'billing_bill_payment_text' => ['name' => 'billing_bill_payment_text', 'type' => 'string', 'internal' => 'paymentText'],
'billing_out_paymentterms' => ['name' => 'billing_out_paymentterms', 'type' => 'int', 'internal' => 'terms'], 'billing_bill_paymentterms' => ['name' => 'billing_bill_paymentterms', 'type' => 'int', 'internal' => 'terms'],
'billing_out_paymentterms_text' => ['name' => 'billing_out_paymentterms_text', 'type' => 'string', 'internal' => 'termsText'], 'billing_bill_paymentterms_text' => ['name' => 'billing_bill_paymentterms_text', 'type' => 'string', 'internal' => 'termsText'],
'billing_out_ship_type' => ['name' => 'billing_out_ship_type', 'type' => 'int', 'internal' => 'shipping'], 'billing_bill_ship_type' => ['name' => 'billing_bill_ship_type', 'type' => 'int', 'internal' => 'shipping'],
'billing_out_ship_text' => ['name' => 'billing_out_ship_text', 'type' => 'string', 'internal' => 'shippingText'], 'billing_bill_ship_text' => ['name' => 'billing_bill_ship_text', 'type' => 'string', 'internal' => 'shippingText'],
'billing_out_client' => ['name' => 'billing_out_client', 'type' => 'int', 'internal' => 'client'], 'billing_bill_client' => ['name' => 'billing_bill_client', 'type' => 'int', 'internal' => 'client'],
'billing_out_created_by' => ['name' => 'billing_out_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'billing_bill_supplier' => ['name' => 'billing_bill_supplier', 'type' => 'int', 'internal' => 'supplier'],
'billing_out_performance_date' => ['name' => 'billing_out_performance_date', 'type' => 'DateTime', 'internal' => 'performanceDate', 'readonly' => true], 'billing_bill_created_by' => ['name' => 'billing_bill_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'billing_out_created_at' => ['name' => 'billing_out_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], 'billing_bill_performance_date' => ['name' => 'billing_bill_performance_date', 'type' => 'DateTime', 'internal' => 'performanceDate', 'readonly' => true],
'billing_bill_created_at' => ['name' => 'billing_bill_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
]; ];
/** /**
@ -85,10 +88,16 @@ final class BillMapper extends DataMapperAbstract
protected static array $hasMany = [ protected static array $hasMany = [
'elements' => [ 'elements' => [
'mapper' => BillElementMapper::class, 'mapper' => BillElementMapper::class,
'table' => 'billing_out_element', 'table' => 'billing_bill_element',
'self' => 'billing_out_element_bill', 'self' => 'billing_bill_element_bill',
'external' => null, 'external' => null,
], ],
'media' => [
'mapper' => MediaMapper::class,
'table' => 'billing_bill_media',
'external' => 'billing_bill_media_dst',
'self' => 'billing_bill_media_src',
],
]; ];
/** /**
@ -100,11 +109,11 @@ final class BillMapper extends DataMapperAbstract
protected static array $ownsOne = [ protected static array $ownsOne = [
'type' => [ 'type' => [
'mapper' => BillTypeMapper::class, 'mapper' => BillTypeMapper::class,
'external' => 'billing_out_type', 'external' => 'billing_bill_type',
], ],
'referral' => [ 'referral' => [
'mapper' => AccountMapper::class, 'mapper' => AccountMapper::class,
'external' => 'billing_out_referral', 'external' => 'billing_bill_referral',
], ],
]; ];
@ -117,11 +126,15 @@ final class BillMapper extends DataMapperAbstract
protected static array $belongsTo = [ protected static array $belongsTo = [
'createdBy' => [ 'createdBy' => [
'mapper' => AccountMapper::class, 'mapper' => AccountMapper::class,
'external' => 'billing_out_created_by', 'external' => 'billing_bill_created_by',
], ],
'client' => [ 'client' => [
'mapper' => ClientMapper::class, 'mapper' => ClientMapper::class,
'external' => 'billing_out_client', 'external' => 'billing_bill_client',
],
'supplier' => [
'mapper' => SupplierMapper::class,
'external' => 'billing_bill_supplier',
], ],
]; ];
@ -131,7 +144,7 @@ final class BillMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'billing_out_id'; protected static string $primaryField = 'billing_bill_id';
/** /**
* Primary table. * Primary table.
@ -139,18 +152,18 @@ final class BillMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'billing_out'; protected static string $table = 'billing_bill';
public static function getSalesByItemId(int $id, \DateTime $start, \DateTime $end) : Money public static function getSalesByItemId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_out_element_total_salesprice_net)') $result = $query->select('SUM(billing_bill_element_total_salesprice_net)')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) ->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
->execute() ->execute()
->fetch(); ->fetch();
@ -160,11 +173,11 @@ final class BillMapper extends DataMapperAbstract
public static function getSalesByClientId(int $id, \DateTime $start, \DateTime $end) : Money public static function getSalesByClientId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_out_net)') $result = $query->select('SUM(billing_bill_net)')
->from(self::$table) ->from(self::$table)
->where(self::$table . '.billing_out_client', '=', $id) ->where(self::$table . '.billing_bill_client', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) ->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
->execute() ->execute()
->fetch(); ->fetch();
@ -174,13 +187,13 @@ final class BillMapper extends DataMapperAbstract
public static function getAvgSalesPriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money public static function getAvgSalesPriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select('SUM(billing_out_element_single_salesprice_net)', 'COUNT(billing_out_element_total_salesprice_net)') $result = $query->select('SUM(billing_bill_element_single_salesprice_net)', 'COUNT(billing_bill_element_total_salesprice_net)')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) ->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
->execute() ->execute()
->fetch(); ->fetch();
@ -191,12 +204,12 @@ final class BillMapper extends DataMapperAbstract
{ {
// @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_out_performance_date') $result = $query->select('billing_bill_performance_date')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
->orderBy('billing_out_id', 'DESC') ->orderBy('billing_bill_id', 'DESC')
->limit(1) ->limit(1)
->execute() ->execute()
->fetch(); ->fetch();
@ -208,10 +221,10 @@ final class BillMapper extends DataMapperAbstract
{ {
// @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_out_performance_date') $result = $query->select('billing_bill_performance_date')
->from(self::$table) ->from(self::$table)
->where(self::$table . '.billing_out_client', '=', $id) ->where(self::$table . '.billing_bill_client', '=', $id)
->orderBy('billing_out_id', 'DESC') ->orderBy('billing_bill_id', 'DESC')
->limit(1) ->limit(1)
->execute() ->execute()
->fetch(); ->fetch();
@ -235,8 +248,8 @@ final class BillMapper extends DataMapperAbstract
$query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query ??= self::getQuery(null, [], RelationType::ALL, $depth);
$query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_' . $depth) $query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_' . $depth)
->on(self::$table . '_' . $depth . '.billing_out_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_bill') ->on(self::$table . '_' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_item', '=', $id)
->limit($limit); ->limit($limit);
if (!empty(self::$createdAt)) { if (!empty(self::$createdAt)) {
@ -255,7 +268,7 @@ final class BillMapper extends DataMapperAbstract
// @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(null, [], RelationType::ALL, $depth);
$query->where(self::$table . '_' . $depth . '.billing_out_client', '=', $id) $query->where(self::$table . '_' . $depth . '.billing_bill_client', '=', $id)
->limit($limit); ->limit($limit);
if (!empty(self::$createdAt)) { if (!empty(self::$createdAt)) {
@ -272,14 +285,14 @@ final class BillMapper extends DataMapperAbstract
$depth = 3; $depth = 3;
$query ??= ClientMapper::getQuery(null, [], RelationType::ALL, $depth); $query ??= ClientMapper::getQuery(null, [], RelationType::ALL, $depth);
$query->selectAs('SUM(billing_out_element_total_salesprice_net)', 'net_sales') $query->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales')
->leftJoin(self::$table, self::$table . '_' . $depth) ->leftJoin(self::$table, self::$table . '_' . $depth)
->on(ClientMapper::getTable() . '_' . $depth . '.clientmgmt_client_id', '=', self::$table . '_' . $depth . '.billing_out_client') ->on(ClientMapper::getTable() . '_' . $depth . '.clientmgmt_client_id', '=', self::$table . '_' . $depth . '.billing_bill_client')
->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_' . $depth) ->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_' . $depth)
->on(self::$table . '_' . $depth . '.billing_out_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_bill') ->on(self::$table . '_' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_item', '=', $id)
->andWhere(self::$table . '_' . $depth . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '_' . $depth . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '_' . $depth . '.billing_out_performance_date', '<=', $end) ->andWhere(self::$table . '_' . $depth . '.billing_bill_performance_date', '<=', $end)
->orderBy('net_sales', 'DESC') ->orderBy('net_sales', 'DESC')
->limit($limit) ->limit($limit)
->groupBy(ClientMapper::getTable() . '_' . $depth . '.clientmgmt_client_id'); ->groupBy(ClientMapper::getTable() . '_' . $depth . '.clientmgmt_client_id');
@ -294,15 +307,15 @@ final class BillMapper extends DataMapperAbstract
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select(CountryMapper::getTable() . '.country_region') $result = $query->select(CountryMapper::getTable() . '.country_region')
->selectAs('SUM(billing_out_element_total_salesprice_net)', 'net_sales') ->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
->leftJoin(CountryMapper::getTable()) ->leftJoin(CountryMapper::getTable())
->on(self::$table . '.billing_out_billCountry', '=', CountryMapper::getTable() . '.country_code2') ->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) ->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
->groupBy(CountryMapper::getTable() . '.country_region') ->groupBy(CountryMapper::getTable() . '.country_region')
->execute() ->execute()
->fetchAll(\PDO::FETCH_KEY_PAIR); ->fetchAll(\PDO::FETCH_KEY_PAIR);
@ -314,15 +327,15 @@ final class BillMapper extends DataMapperAbstract
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->select(CountryMapper::getTable() . '.country_code2') $result = $query->select(CountryMapper::getTable() . '.country_code2')
->selectAs('SUM(billing_out_element_total_salesprice_net)', 'net_sales') ->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
->leftJoin(CountryMapper::getTable()) ->leftJoin(CountryMapper::getTable())
->on(self::$table . '.billing_out_billCountry', '=', CountryMapper::getTable() . '.country_code2') ->on(self::$table . '.billing_bill_billCountry', '=', CountryMapper::getTable() . '.country_code2')
->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) ->andWhere(self::$table . '.billing_bill_performance_date', '<=', $end)
->groupBy(CountryMapper::getTable() . '.country_code2') ->groupBy(CountryMapper::getTable() . '.country_code2')
->orderBy('net_sales', 'DESC') ->orderBy('net_sales', 'DESC')
->limit($limit) ->limit($limit)
@ -335,16 +348,16 @@ final class BillMapper extends DataMapperAbstract
public static function getItemMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array public static function getItemMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_out_element_total_salesprice_net)', 'net_sales') $result = $query->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales')
->selectAs('SUM(billing_out_element_total_purchaseprice_net)', 'net_costs') ->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', 'net_costs')
->selectAs('YEAR(billing_out_performance_date)', 'year') ->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_out_performance_date)', 'month') ->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::$table) ->from(self::$table)
->leftJoin(BillElementMapper::getTable()) ->leftJoin(BillElementMapper::getTable())
->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill')
->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_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()
@ -356,14 +369,14 @@ final class BillMapper extends DataMapperAbstract
public static function getClientMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array public static function getClientMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array
{ {
$query = new Builder(self::$db); $query = new Builder(self::$db);
$result = $query->selectAs('SUM(billing_out_net)', 'net_sales') $result = $query->selectAs('SUM(billing_bill_net)', 'net_sales')
->selectAs('SUM(billing_out_costs)', 'net_costs') ->selectAs('SUM(billing_bill_costs)', 'net_costs')
->selectAs('YEAR(billing_out_performance_date)', 'year') ->selectAs('YEAR(billing_bill_performance_date)', 'year')
->selectAs('MONTH(billing_out_performance_date)', 'month') ->selectAs('MONTH(billing_bill_performance_date)', 'month')
->from(self::$table) ->from(self::$table)
->where(self::$table . '.billing_out_client', '=', $id) ->where(self::$table . '.billing_bill_client', '=', $id)
->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) ->andWhere(self::$table . '.billing_bill_performance_date', '>=', $start)
->andWhere(self::$table . '.billing_out_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()

0
Models/BillStatus.php Normal file → Executable file
View File

View File

@ -0,0 +1,34 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Billing\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Billing\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Task type enum.
*
* @package Modules\Billing\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class BillTransferType extends Enum
{
public const SALES = 1;
public const PURCHASE = 2;
public const STOCK = 4;
}

4
Models/BillType.php Normal file → Executable file
View File

@ -34,6 +34,10 @@ class BillType
*/ */
protected int $id = 0; protected int $id = 0;
public int $transferType = BillTransferType::SALES;
public bool $transferStock = true;
/** /**
* Localization * Localization
* *

0
Models/BillTypeL11n.php Normal file → Executable file
View File

0
Models/BillTypeL11nMapper.php Normal file → Executable file
View File

2
Models/BillTypeMapper.php Normal file → Executable file
View File

@ -34,6 +34,8 @@ final class BillTypeMapper extends DataMapperAbstract
*/ */
protected static array $columns = [ protected static array $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_stock' => ['name' => 'billing_type_transfer_stock', 'type' => 'bool', 'internal' => 'transferStock'],
]; ];
/** /**

0
Models/NullBill.php Normal file → Executable file
View File

0
Models/NullBillType.php Normal file → Executable file
View File

0
Models/PermissionState.php Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
Theme/Backend/Lang/Navigation.en.lang.php Normal file → Executable file
View File

0
Theme/Backend/Lang/en.lang.php Normal file → Executable file
View File

0
Theme/Backend/invoice-archive.tpl.php Normal file → Executable file
View File

4
Theme/Backend/invoice-create.tpl.php Normal file → Executable file
View File

@ -258,8 +258,8 @@ echo $this->getData('nav')->render(); ?>
<tbody> <tbody>
<tr> <tr>
<td><?= $this->printHtml($this->request->getOrigin()); ?> <td><?= $this->printHtml($this->request->getOrigin()); ?>
<td><?= $this->printHtml($this->request->getHeader()->getAccount()); ?> <td><?= $this->printHtml((string) $this->request->header->account); ?>
<td><?= $this->printHtml($this->request->getHeader()->getAccount()); ?> <td><?= $this->printHtml((string) $this->request->header->account); ?>
<td>Create Invoice <td>Create Invoice
<td><?= $this->printHtml((new \DateTime('now'))->format('Y-m-d H:i:s')); ?> <td><?= $this->printHtml((new \DateTime('now'))->format('Y-m-d H:i:s')); ?>
</table> </table>

0
Theme/Backend/purchase-invoice-list.tpl.php Normal file → Executable file
View File

10
Theme/Backend/sales-bill-list.tpl.php Normal file → Executable file
View File

@ -46,11 +46,11 @@ echo $this->getData('nav')->render(); ?>
<td><a href="<?= $url; ?>"><?= $value->getNumber(); ?></a> <td><a href="<?= $url; ?>"><?= $value->getNumber(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->type->getL11n(); ?></a> <td><a href="<?= $url; ?>"><?= $value->type->getL11n(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->client->number; ?></a> <td><a href="<?= $url; ?>"><?= $value->client->number; ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->client->profile->account->name3 . ' ' . $value->client->profile->account->name2 . ' ' . $value->client->profile->account->name1); ?></a> <td><a href="<?= $url; ?>"><?= $this->printHtml($value->billTo); ?></a>
<td><a href="<?= $url; ?>"><?= $value->client->mainAddress->address; ?></a> <td><a href="<?= $url; ?>"><?= $value->billAddress; ?></a>
<td><a href="<?= $url; ?>"><?= $value->client->mainAddress->postal; ?></a> <td><a href="<?= $url; ?>"><?= $value->billZip; ?></a>
<td><a href="<?= $url; ?>"><?= $value->client->mainAddress->city; ?></a> <td><a href="<?= $url; ?>"><?= $value->billCity; ?></a>
<td><a href="<?= $url; ?>"><?= $value->client->mainAddress->getCountry(); ?></a> <td><a href="<?= $url; ?>"><?= $value->billCountry; ?></a>
<td><a href="<?= $url; ?>"><?= $value->net->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->net->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->gross->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->gross->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->profit->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->profit->getCurrency(); ?></a>

13
Theme/Backend/sales-bill.tpl.php Normal file → Executable file
View File

@ -12,6 +12,8 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/** /**
* @var \phpOMS\Views\View $this * @var \phpOMS\Views\View $this
*/ */
@ -19,6 +21,8 @@ declare(strict_types=1);
$bill = $this->getData('bill'); $bill = $this->getData('bill');
$elements = $bill->getElements(); $elements = $bill->getElements();
$billPdf = $bill->getMediaByType('bill');
echo $this->getData('nav')->render(); ?> echo $this->getData('nav')->render(); ?>
<div class="tabview tab-2"> <div class="tabview tab-2">
@ -185,6 +189,15 @@ echo $this->getData('nav')->render(); ?>
</div> </div>
<input type="radio" id="c-tab-3" name="tabular-2"> <input type="radio" id="c-tab-3" name="tabular-2">
<div class="tab"> <div class="tab">
<div class="row">
<div class="col-xs-12">
<section id="mediaFile" class="portlet">
<div class="portlet-body">
<iframe style="min-height: 600px;" data-form="iUiSettings" data-name="iframeHelper" id="iHelperFrame" src="<?= UriFactory::build('{/backend}Resources/mozilla/Pdf/web/viewer.html?{?}&file=' . ($billPdf->isAbsolute ? '' : '/../../../../') . $billPdf->getPath()); ?>" allowfullscreen></iframe>
</div>
</section>
</div>
</div>
</div> </div>
<input type="radio" id="c-tab-4" name="tabular-2"> <input type="radio" id="c-tab-4" name="tabular-2">
<div class="tab"> <div class="tab">

0
composer.json Normal file → Executable file
View File

0
composer.lock generated Normal file → Executable file
View File

1
info.json Normal file → Executable file
View File

@ -19,6 +19,7 @@
"dependencies": { "dependencies": {
"Admin": "1.0.0", "Admin": "1.0.0",
"Sales": "1.0.0", "Sales": "1.0.0",
"Media": "1.0.0",
"ClientManagement": "1.0.0" "ClientManagement": "1.0.0"
}, },
"providing": { "providing": {

0
tests/Autoloader.php Normal file → Executable file
View File

0
tests/Bootstrap.php Normal file → Executable file
View File

0
tests/phpunit_default.xml Normal file → Executable file
View File