diff --git a/.directory b/.directory old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json old mode 100644 new mode 100755 index ba3947a..3fdc64d --- a/Admin/Install/Media.install.json +++ b/Admin/Install/Media.install.json @@ -1,18 +1,21 @@ [ { "type": "collection", + "create_directory": true, "name": "Billing", "virtualPath": "/Modules", "user": 1 }, { "type": "collection", + "create_directory": true, "name": "Templates", "virtualPath": "/Modules/Billing", "user": 1 }, { "type": "collection", + "create_directory": true, "name": "Bills", "virtualPath": "/Modules/Billing", "user": 1 diff --git a/Admin/Install/Media.php b/Admin/Install/Media.php old mode 100644 new mode 100755 index df96a81..bb09d89 --- a/Admin/Install/Media.php +++ b/Admin/Install/Media.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Modules\Billing\Admin\Install; -use Model\CoreSettings; use Model\Setting; +use Model\SettingMapper; use phpOMS\DataStorage\Database\DatabasePool; /** @@ -42,9 +42,9 @@ class Media { $media = \Modules\Media\Admin\Installer::installExternal($dbPool, ['path' => __DIR__ . '/Media.install.json']); - $defaultTemplate = \reset($result['upload']); + $defaultTemplate = \reset($media['upload'][0]); $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')); } } diff --git a/Admin/Install/Media/bill.pdf.php b/Admin/Install/Media/bill.pdf.php old mode 100644 new mode 100755 index b4994de..84225be --- a/Admin/Install/Media/bill.pdf.php +++ b/Admin/Install/Media/bill.pdf.php @@ -284,4 +284,4 @@ mpdf--> '); -$mpdf->Output(); +$mpdf->Output($this->getData('path'), \Mpdf\Output\Destination::FILE); diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json old mode 100644 new mode 100755 diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php old mode 100644 new mode 100755 diff --git a/Admin/Install/WarehouseManagement.php b/Admin/Install/WarehouseManagement.php new file mode 100644 index 0000000..65b0248 --- /dev/null +++ b/Admin/Install/WarehouseManagement.php @@ -0,0 +1,67 @@ +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'); + } +} diff --git a/Admin/Install/db.json b/Admin/Install/db.json old mode 100644 new mode 100755 index 10a833b..da8d653 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -8,6 +8,18 @@ "null": false, "primary": 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": { - "name": "billing_out", + "billing_bill": { + "name": "billing_bill", "fields": { - "billing_out_id": { - "name": "billing_out_id", + "billing_bill_id": { + "name": "billing_bill_id", "type": "INT", "null": false, "primary": true, "autoincrement": true }, - "billing_out_number": { - "name": "billing_out_number", + "billing_bill_number": { + "name": "billing_bill_number", "type": "VARCHAR(255)", "null": false }, - "billing_out_info": { - "name": "billing_out_info", + "billing_bill_info": { + "name": "billing_bill_info", "type": "TEXT", "default": null, "null": true }, - "billing_out_status": { - "name": "billing_out_status", + "billing_bill_status": { + "name": "billing_bill_status", "type": "TINYINT", "null": false }, - "billing_out_type": { - "name": "billing_out_type", + "billing_bill_type": { + "name": "billing_bill_type", "type": "INT", "null": false, "foreignTable": "billing_type", "foreignKey": "billing_type_id" }, - "billing_out_client": { - "name": "billing_out_client", + "billing_bill_supplier": { + "name": "billing_bill_supplier", "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", "foreignKey": "clientmgmt_client_id" }, - "billing_out_shipTo": { - "name": "billing_out_shipTo", + "billing_bill_stock_from": { + "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)", "null": false }, - "billing_out_shipFAO": { - "name": "billing_out_shipFAO", + "billing_bill_shipFAO": { + "name": "billing_bill_shipFAO", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_shipAddr": { - "name": "billing_out_shipAddr", + "billing_bill_shipAddr": { + "name": "billing_bill_shipAddr", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_shipCity": { - "name": "billing_out_shipCity", + "billing_bill_shipCity": { + "name": "billing_bill_shipCity", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_shipZip": { - "name": "billing_out_shipZip", + "billing_bill_shipZip": { + "name": "billing_bill_shipZip", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_shipCountry": { - "name": "billing_out_shipCountry", + "billing_bill_shipCountry": { + "name": "billing_bill_shipCountry", "type": "VARCHAR(3)", "default": null, "null": true }, - "billing_out_billTo": { - "name": "billing_out_billTo", + "billing_bill_billTo": { + "name": "billing_bill_billTo", "type": "VARCHAR(255)", "null": false }, - "billing_out_billFAO": { - "name": "billing_out_billFAO", + "billing_bill_billFAO": { + "name": "billing_bill_billFAO", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_billAddr": { - "name": "billing_out_billAddr", + "billing_bill_billAddr": { + "name": "billing_bill_billAddr", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_billCity": { - "name": "billing_out_billCity", + "billing_bill_billCity": { + "name": "billing_bill_billCity", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_billZip": { - "name": "billing_out_billZip", + "billing_bill_billZip": { + "name": "billing_bill_billZip", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_billCountry": { - "name": "billing_out_billCountry", + "billing_bill_billCountry": { + "name": "billing_bill_billCountry", "type": "VARCHAR(3)", "default": null, "null": true }, - "billing_out_created_at": { - "name": "billing_out_created_at", + "billing_bill_created_at": { + "name": "billing_bill_created_at", "type": "DATETIME", "null": false }, - "billing_out_performance_date": { - "name": "billing_out_performance_date", + "billing_bill_performance_date": { + "name": "billing_bill_performance_date", "type": "DATETIME", "null": false }, - "billing_out_created_by": { - "name": "billing_out_created_by", + "billing_bill_created_by": { + "name": "billing_bill_created_by", "type": "INT", "null": false, "foreignTable": "account", "foreignKey": "account_id" }, - "billing_out_gross": { - "name": "billing_out_gross", + "billing_bill_gross": { + "name": "billing_bill_gross", "type": "INT", "null": false }, - "billing_out_net": { - "name": "billing_out_net", + "billing_bill_net": { + "name": "billing_bill_net", "type": "INT", "null": false }, - "billing_out_costs": { - "name": "billing_out_costs", + "billing_bill_costs": { + "name": "billing_bill_costs", "type": "INT", "null": false }, - "billing_out_profit": { - "name": "billing_out_profit", + "billing_bill_profit": { + "name": "billing_bill_profit", "type": "INT", "null": false }, - "billing_out_currency": { - "name": "billing_out_currency", + "billing_bill_currency": { + "name": "billing_bill_currency", "type": "INT", "null": false }, - "billing_out_referral": { - "name": "billing_out_referral", + "billing_bill_referral": { + "name": "billing_bill_referral", "type": "INT", "null": true, "default": null, "foreignTable": "account", "foreignKey": "account_id" }, - "billing_out_referral_name": { - "name": "billing_out_referral_name", + "billing_bill_referral_name": { + "name": "billing_bill_referral_name", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_reference": { - "name": "billing_out_reference", + "billing_bill_reference": { + "name": "billing_bill_reference", "type": "INT", "null": false }, - "billing_out_payment": { - "name": "billing_out_payment", + "billing_bill_payment": { + "name": "billing_bill_payment", "type": "INT", "null": false }, - "billing_out_payment_text": { - "name": "billing_out_payment_text", + "billing_bill_payment_text": { + "name": "billing_bill_payment_text", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_paymentterms": { - "name": "billing_out_paymentterms", + "billing_bill_paymentterms": { + "name": "billing_bill_paymentterms", "type": "INT", "null": false }, - "billing_out_paymentterms_text": { - "name": "billing_out_paymentterms_text", + "billing_bill_paymentterms_text": { + "name": "billing_bill_paymentterms_text", "type": "VARCHAR(255)", "default": null, "null": true }, - "billing_out_ship_type": { - "name": "billing_out_ship_type", + "billing_bill_ship_type": { + "name": "billing_bill_ship_type", "type": "INT", "null": false }, - "billing_out_ship_text": { + "billing_bill_ship_text": { "name": "billing_bill_ship_text", "type": "VARCHAR(255)", "default": null, @@ -249,168 +282,194 @@ } } }, - "billing_out_element": { - "name": "billing_out_element", + "billing_bill_element": { + "name": "billing_bill_element", "fields": { - "billing_out_element_id": { - "name": "billing_out_element_id", + "billing_bill_element_id": { + "name": "billing_bill_element_id", "type": "INT", "null": false, "primary": true, "autoincrement": true }, - "billing_out_element_order": { - "name": "billing_out_element_order", + "billing_bill_element_order": { + "name": "billing_bill_element_order", "type": "INT", "null": false }, - "billing_out_element_item": { - "name": "billing_out_element_item", + "billing_bill_element_item": { + "name": "billing_bill_element_item", "type": "INT", "null": true, "default": null }, - "billing_out_element_item_segment": { - "name": "billing_out_element_item_segment", + "billing_bill_element_item_segment": { + "name": "billing_bill_element_item_segment", "type": "INT", "default": null, "null": true }, - "billing_out_element_item_number": { - "name": "billing_out_element_item_number", + "billing_bill_element_item_number": { + "name": "billing_bill_element_item_number", "type": "VARCHAR(255)", "null": false }, - "billing_out_element_item_name": { - "name": "billing_out_element_item_name", + "billing_bill_element_item_name": { + "name": "billing_bill_element_item_name", "type": "VARCHAR(255)", "null": false }, - "billing_out_element_item_desc": { - "name": "billing_out_element_item_desc", + "billing_bill_element_item_desc": { + "name": "billing_bill_element_item_desc", "type": "VARCHAR(255)", "null": false }, - "billing_out_element_quantity": { - "name": "billing_out_element_quantity", + "billing_bill_element_quantity": { + "name": "billing_bill_element_quantity", "type": "INT", "null": false }, - "billing_out_element_single_salesprice_net": { - "name": "billing_out_element_single_salesprice_net", + "billing_bill_element_single_salesprice_net": { + "name": "billing_bill_element_single_salesprice_net", "type": "BIGINT", "null": true, "default": null }, - "billing_out_element_single_purchaseprice_net": { - "name": "billing_out_element_single_purchaseprice_net", + "billing_bill_element_single_purchaseprice_net": { + "name": "billing_bill_element_single_purchaseprice_net", "type": "BIGINT", "null": true, "default": null }, - "billing_out_element_total_salesprice_net": { - "name": "billing_out_element_total_salesprice_net", + "billing_bill_element_total_salesprice_net": { + "name": "billing_bill_element_total_salesprice_net", "type": "BIGINT", "null": true, "default": null }, - "billing_out_element_total_purchaseprice_net": { - "name": "billing_out_element_total_purchaseprice_net", + "billing_bill_element_total_purchaseprice_net": { + "name": "billing_bill_element_total_purchaseprice_net", "type": "BIGINT", "null": true, "default": null }, - "billing_out_element_price_discount_single": { - "name": "billing_out_element_price_discount_single", + "billing_bill_element_price_discount_single": { + "name": "billing_bill_element_price_discount_single", "type": "INT", "null": true, "default": null }, - "billing_out_element_price_discount_total": { - "name": "billing_out_element_price_discount_total", + "billing_bill_element_price_discount_total": { + "name": "billing_bill_element_price_discount_total", "type": "INT", "null": true, "default": null }, - "billing_out_element_percentage_discount_single": { - "name": "billing_out_element_percentage_discount_single", + "billing_bill_element_percentage_discount_single": { + "name": "billing_bill_element_percentage_discount_single", "type": "INT", "null": true, "default": null }, - "billing_out_element_percentage_discount_total": { - "name": "billing_out_element_percentage_discount_total", + "billing_bill_element_percentage_discount_total": { + "name": "billing_bill_element_percentage_discount_total", "type": "INT", "null": true, "default": null }, - "billing_out_element_quantity_discount": { - "name": "billing_out_element_quantity_discount", + "billing_bill_element_quantity_discount": { + "name": "billing_bill_element_quantity_discount", "type": "INT", "null": true, "default": null }, - "billing_out_element_price_single_net": { - "name": "billing_out_element_price_single_net", + "billing_bill_element_price_single_net": { + "name": "billing_bill_element_price_single_net", "type": "INT", "null": true, "default": null }, - "billing_out_element_price_total_net": { - "name": "billing_out_element_price_total_net", + "billing_bill_element_price_total_net": { + "name": "billing_bill_element_price_total_net", "type": "INT", "null": true, "default": null }, - "billing_out_element_tax_price": { - "name": "billing_out_element_tax_price", + "billing_bill_element_tax_price": { + "name": "billing_bill_element_tax_price", "type": "INT", "null": true, "default": null }, - "billing_out_element_tax_type": { - "name": "billing_out_element_tax_type", + "billing_bill_element_tax_type": { + "name": "billing_bill_element_tax_type", "type": "INT", "null": true, "default": null }, - "billing_out_element_tax_percentage": { - "name": "billing_out_element_tax_percentage", + "billing_bill_element_tax_percentage": { + "name": "billing_bill_element_tax_percentage", "type": "INT", "null": true, "default": null }, - "billing_out_element_price_single_gross": { - "name": "billing_out_element_price_single_gross", + "billing_bill_element_price_single_gross": { + "name": "billing_bill_element_price_single_gross", "type": "INT", "null": true, "default": null }, - "billing_out_element_price_total_gross": { - "name": "billing_out_element_price_total_gross", + "billing_bill_element_price_total_gross": { + "name": "billing_bill_element_price_total_gross", "type": "INT", "null": true, "default": null }, - "billing_out_element_bill": { - "name": "billing_out_element_bill", + "billing_bill_element_bill": { + "name": "billing_bill_element_bill", "type": "INT", "null": false, - "foreignTable": "billing_out", - "foreignKey": "billing_out_id" + "foreignTable": "billing_bill", + "foreignKey": "billing_bill_id" }, - "billing_out_element_promotion": { - "name": "billing_out_element_promotion", + "billing_bill_element_promotion": { + "name": "billing_bill_element_promotion", "type": "INT", "default": null, "null": true }, - "billing_out_element_event": { - "name": "billing_out_element_event", + "billing_bill_element_event": { + "name": "billing_bill_element_event", "type": "INT", "default": null, "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" + } + } } } \ No newline at end of file diff --git a/Admin/Installer.php b/Admin/Installer.php old mode 100644 new mode 100755 index d6f8485..178d344 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -18,6 +18,7 @@ use Modules\Billing\Models\BillType; use Modules\Billing\Models\BillTypeL11n; use Modules\Billing\Models\BillTypeL11nMapper; use Modules\Billing\Models\BillTypeMapper; +use Modules\Billing\Models\BillTransferType; use phpOMS\Config\SettingsInterface; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Localization\ISO639x1Enum; @@ -41,44 +42,120 @@ final class Installer extends InstallerAbstract { parent::install($dbPool, $info, $cfgHandler); - self::createBillTypes(); + self::createOutgoingBillTypes(); + self::createIncomingBillTypes(); + self::createTransferBillTypes(); } /** - * Install default bill types + * Install default outgoing bill types * * @return BillType[] * * @since 1.0.0 */ - private static function createBillTypes() : array + private static function createOutgoingBillTypes() : array { $billType = []; $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)); $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)); $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)); $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)); $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)); $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)); 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 []; + } } diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php old mode 100644 new mode 100755 diff --git a/Admin/Status.php b/Admin/Status.php old mode 100644 new mode 100755 diff --git a/Admin/Uninstaller.php b/Admin/Uninstaller.php old mode 100644 new mode 100755 diff --git a/Admin/Updater.php b/Admin/Updater.php old mode 100644 new mode 100755 diff --git a/Controller/ApiController.php b/Controller/ApiController.php old mode 100644 new mode 100755 index 0590f00..6c005d0 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -22,6 +22,7 @@ use Modules\Billing\Models\BillMapper; use Modules\Billing\Models\NullBillType; use Modules\ClientManagement\Models\ClientMapper; use Modules\ClientManagement\Models\NullClient; +use Modules\SupplierManagement\Models\SupplierMapper; use Modules\ItemManagement\Models\ItemMapper; use phpOMS\Localization\Money; use phpOMS\Message\Http\RequestStatusCode; @@ -29,6 +30,12 @@ use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; 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. @@ -80,16 +87,23 @@ final class ApiController extends Controller */ 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->setCreatedBy(new NullAccount($request->header->account)); $bill->number = '{y}-{id}'; // @todo: use admin defined format $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.) - $bill->billCountry = $request->getData('billtocountry') ?? $client->mainAddress->getCountry(); + ?? ($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->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->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'); return $bill; @@ -252,8 +266,52 @@ final class ApiController extends Controller */ public function apiBillPdfArchiveCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void { - $this->apiBillPdfCreate($request, $response, $data); - // upload pdf to media module + Autoloader::addPath(__DIR__ . '/../../../Resources/'); + + $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 { - $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 } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php old mode 100644 new mode 100755 index db8eb54..b0a8057 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -52,17 +52,17 @@ final class BackendController extends Controller if ($request->getData('ptype') === 'p') { $view->setData('bills', 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') { $view->setData('bills', 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 { $view->setData('bills', BillMapper::withConditional('language', $response->getLanguage(), [BillTypeL11n::class]) - ::getAfterPivot(0, limit: 25, depth: 4) + ::getAfterPivot(0, limit: 25, depth: 3) ); } diff --git a/Controller/Controller.php b/Controller/Controller.php old mode 100644 new mode 100755 diff --git a/Docs/Dev/en/SUMMARY.md b/Docs/Dev/en/SUMMARY.md new file mode 100644 index 0000000..e69de29 diff --git a/Docs/Dev/en/structure.md b/Docs/Dev/en/structure.md new file mode 100644 index 0000000..e69de29 diff --git a/Models/Bill.php b/Models/Bill.php old mode 100644 new mode 100755 index 3af86ea..4210b2c --- a/Models/Bill.php +++ b/Models/Bill.php @@ -16,6 +16,7 @@ namespace Modules\Billing\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; +use Modules\Media\Models\Media; use phpOMS\Localization\ISO4217CharEnum; use phpOMS\Localization\Money; @@ -51,9 +52,7 @@ class Bill implements \JsonSerializable * @var int|BillType * @since 1.0.0 */ - public int | - -BillType $type = 0; + public int | BillType $type = 0; /** * Bill status. @@ -96,6 +95,7 @@ BillType $type = 0; public Account $createdBy; public $client = 0; + public $supplier = 0; /** * Receiver. @@ -159,7 +159,7 @@ BillType $type = 0; * @var string * @since 1.0.0 */ - private $billFAO = ''; + public string $billFAO = ''; /** * Billing address. @@ -167,7 +167,7 @@ BillType $type = 0; * @var string * @since 1.0.0 */ - private $billAddress = ''; + public string $billAddress = ''; /** * Billing city. @@ -175,7 +175,7 @@ BillType $type = 0; * @var string * @since 1.0.0 */ - private $billCity = ''; + public string $billCity = ''; /** * Billing zip. @@ -183,7 +183,7 @@ BillType $type = 0; * @var string * @since 1.0.0 */ - private $billZip = ''; + public string $billZip = ''; /** * Billing country. @@ -241,6 +241,14 @@ BillType $type = 0; */ private int $reference = 0; + /** + * Media files + * + * @var array + * @since 1.0.0 + */ + protected array $media = []; + /** * Constructor. * @@ -1211,6 +1219,53 @@ BillType $type = 0; $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} */ diff --git a/Models/BillElement.php b/Models/BillElement.php old mode 100644 new mode 100755 diff --git a/Models/BillElementMapper.php b/Models/BillElementMapper.php old mode 100644 new mode 100755 index 03270a8..c5fffaa --- a/Models/BillElementMapper.php +++ b/Models/BillElementMapper.php @@ -33,18 +33,18 @@ final class BillElementMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'billing_out_element_id' => ['name' => 'billing_out_element_id', 'type' => 'int', 'internal' => 'id'], - 'billing_out_element_order' => ['name' => 'billing_out_element_order', 'type' => 'int', 'internal' => 'order'], - 'billing_out_element_item' => ['name' => 'billing_out_element_item', 'type' => 'int', 'internal' => 'item'], - 'billing_out_element_item_number' => ['name' => 'billing_out_element_item_number', 'type' => 'string', 'internal' => 'itemNumber'], - 'billing_out_element_item_name' => ['name' => 'billing_out_element_item_name', 'type' => 'string', 'internal' => 'itemName'], - 'billing_out_element_item_desc' => ['name' => 'billing_out_element_item_desc', 'type' => 'string', 'internal' => 'itemDescription'], - 'billing_out_element_quantity' => ['name' => 'billing_out_element_quantity', 'type' => 'int', 'internal' => 'quantity'], - 'billing_out_element_single_salesprice_net' => ['name' => 'billing_out_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_out_element_total_salesprice_net' => ['name' => 'billing_out_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_out_element_bill' => ['name' => 'billing_out_element_bill', 'type' => 'int', 'internal' => 'bill'], + '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'], + 'billing_bill_element_item_number' => ['name' => 'billing_bill_element_item_number', 'type' => 'string', 'internal' => 'itemNumber'], + 'billing_bill_element_item_name' => ['name' => 'billing_bill_element_item_name', 'type' => 'string', 'internal' => 'itemName'], + 'billing_bill_element_item_desc' => ['name' => 'billing_bill_element_item_desc', 'type' => 'string', 'internal' => 'itemDescription'], + 'billing_bill_element_quantity' => ['name' => 'billing_bill_element_quantity', 'type' => 'int', 'internal' => 'quantity'], + 'billing_bill_element_single_salesprice_net' => ['name' => 'billing_bill_element_single_salesprice_net', 'type' => 'Serializable', 'internal' => 'singleSalesPriceNet'], + 'billing_bill_element_single_purchaseprice_net' => ['name' => 'billing_bill_element_single_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'singlePurchasePriceNet'], + 'billing_bill_element_total_salesprice_net' => ['name' => 'billing_bill_element_total_salesprice_net', 'type' => 'Serializable', 'internal' => 'totalSalesPriceNet'], + 'billing_bill_element_total_purchaseprice_net' => ['name' => 'billing_bill_element_total_purchaseprice_net', 'type' => 'Serializable', 'internal' => 'totalPurchasePriceNet'], + '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 = [ 'bill' => [ 'mapper' => BillMapper::class, - 'external' => 'billing_out_element_bill', + 'external' => 'billing_bill_element_bill', ], ]; @@ -66,7 +66,7 @@ final class BillElementMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - public static string $primaryField = 'billing_out_element_id'; + public static string $primaryField = 'billing_bill_element_id'; /** * Primary table. @@ -74,5 +74,5 @@ final class BillElementMapper extends DataMapperAbstract * @var string * @since 1.0.0 */ - public static string $table = 'billing_out_element'; + public static string $table = 'billing_bill_element'; } diff --git a/Models/BillMapper.php b/Models/BillMapper.php old mode 100644 new mode 100755 index ec439c7..79427e8 --- a/Models/BillMapper.php +++ b/Models/BillMapper.php @@ -16,6 +16,8 @@ namespace Modules\Billing\Models; use Modules\Admin\Models\AccountMapper; use Modules\ClientManagement\Models\ClientMapper; +use Modules\SupplierManagement\Models\SupplierMapper; +use Modules\Media\Models\MediaMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\RelationType; @@ -39,41 +41,42 @@ final class BillMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'billing_out_id' => ['name' => 'billing_out_id', 'type' => 'int', 'internal' => 'id'], - 'billing_out_number' => ['name' => 'billing_out_number', 'type' => 'string', 'internal' => 'number'], - 'billing_out_type' => ['name' => 'billing_out_type', 'type' => 'int', 'internal' => 'type'], - 'billing_out_info' => ['name' => 'billing_out_info', 'type' => 'string', 'internal' => 'info'], - 'billing_out_status' => ['name' => 'billing_out_status', 'type' => 'int', 'internal' => 'status'], - 'billing_out_shipTo' => ['name' => 'billing_out_shipTo', 'type' => 'string', 'internal' => 'shipTo'], - 'billing_out_shipFAO' => ['name' => 'billing_out_shipFAO', 'type' => 'string', 'internal' => 'shipFAO'], - 'billing_out_shipAddr' => ['name' => 'billing_out_shipAddr', 'type' => 'string', 'internal' => 'shipAddress'], - 'billing_out_shipCity' => ['name' => 'billing_out_shipCity', 'type' => 'string', 'internal' => 'shipCity'], - 'billing_out_shipZip' => ['name' => 'billing_out_shipZip', 'type' => 'string', 'internal' => 'shipZip'], - 'billing_out_shipCountry' => ['name' => 'billing_out_shipCountry', 'type' => 'string', 'internal' => 'shipCountry'], - 'billing_out_billTo' => ['name' => 'billing_out_billTo', 'type' => 'string', 'internal' => 'billTo'], - 'billing_out_billFAO' => ['name' => 'billing_out_billFAO', 'type' => 'string', 'internal' => 'billFAO'], - 'billing_out_billAddr' => ['name' => 'billing_out_billAddr', 'type' => 'string', 'internal' => 'billAddress'], - 'billing_out_billCity' => ['name' => 'billing_out_billCity', 'type' => 'string', 'internal' => 'billCity'], - 'billing_out_billZip' => ['name' => 'billing_out_billZip', 'type' => 'string', 'internal' => 'billZip'], - 'billing_out_billCountry' => ['name' => 'billing_out_billCountry', 'type' => 'string', 'internal' => 'billCountry'], - 'billing_out_gross' => ['name' => 'billing_out_gross', 'type' => 'Serializable', 'internal' => 'gross'], - 'billing_out_net' => ['name' => 'billing_out_net', 'type' => 'Serializable', 'internal' => 'net'], - 'billing_out_costs' => ['name' => 'billing_out_costs', 'type' => 'Serializable', 'internal' => 'costs'], - 'billing_out_profit' => ['name' => 'billing_out_profit', 'type' => 'Serializable', 'internal' => 'profit'], - 'billing_out_currency' => ['name' => 'billing_out_currency', 'type' => 'int', 'internal' => 'currency'], - 'billing_out_referral' => ['name' => 'billing_out_referral', 'type' => 'int', 'internal' => 'referral'], - 'billing_out_referral_name' => ['name' => 'billing_out_referral_name', 'type' => 'string', 'internal' => 'referralName'], - 'billing_out_reference' => ['name' => 'billing_out_reference', 'type' => 'int', 'internal' => 'reference'], - 'billing_out_payment' => ['name' => 'billing_out_payment', 'type' => 'int', 'internal' => 'payment'], - 'billing_out_payment_text' => ['name' => 'billing_out_payment_text', 'type' => 'string', 'internal' => 'paymentText'], - 'billing_out_paymentterms' => ['name' => 'billing_out_paymentterms', 'type' => 'int', 'internal' => 'terms'], - 'billing_out_paymentterms_text' => ['name' => 'billing_out_paymentterms_text', 'type' => 'string', 'internal' => 'termsText'], - 'billing_out_ship_type' => ['name' => 'billing_out_ship_type', 'type' => 'int', 'internal' => 'shipping'], - 'billing_out_ship_text' => ['name' => 'billing_out_ship_text', 'type' => 'string', 'internal' => 'shippingText'], - 'billing_out_client' => ['name' => 'billing_out_client', 'type' => 'int', 'internal' => 'client'], - 'billing_out_created_by' => ['name' => 'billing_out_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], - 'billing_out_performance_date' => ['name' => 'billing_out_performance_date', 'type' => 'DateTime', 'internal' => 'performanceDate', 'readonly' => true], - 'billing_out_created_at' => ['name' => 'billing_out_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], + 'billing_bill_id' => ['name' => 'billing_bill_id', 'type' => 'int', 'internal' => 'id'], + 'billing_bill_number' => ['name' => 'billing_bill_number', 'type' => 'string', 'internal' => 'number'], + 'billing_bill_type' => ['name' => 'billing_bill_type', 'type' => 'int', 'internal' => 'type'], + 'billing_bill_info' => ['name' => 'billing_bill_info', 'type' => 'string', 'internal' => 'info'], + 'billing_bill_status' => ['name' => 'billing_bill_status', 'type' => 'int', 'internal' => 'status'], + 'billing_bill_shipTo' => ['name' => 'billing_bill_shipTo', 'type' => 'string', 'internal' => 'shipTo'], + 'billing_bill_shipFAO' => ['name' => 'billing_bill_shipFAO', 'type' => 'string', 'internal' => 'shipFAO'], + 'billing_bill_shipAddr' => ['name' => 'billing_bill_shipAddr', 'type' => 'string', 'internal' => 'shipAddress'], + 'billing_bill_shipCity' => ['name' => 'billing_bill_shipCity', 'type' => 'string', 'internal' => 'shipCity'], + 'billing_bill_shipZip' => ['name' => 'billing_bill_shipZip', 'type' => 'string', 'internal' => 'shipZip'], + 'billing_bill_shipCountry' => ['name' => 'billing_bill_shipCountry', 'type' => 'string', 'internal' => 'shipCountry'], + 'billing_bill_billTo' => ['name' => 'billing_bill_billTo', 'type' => 'string', 'internal' => 'billTo'], + 'billing_bill_billFAO' => ['name' => 'billing_bill_billFAO', 'type' => 'string', 'internal' => 'billFAO'], + 'billing_bill_billAddr' => ['name' => 'billing_bill_billAddr', 'type' => 'string', 'internal' => 'billAddress'], + 'billing_bill_billCity' => ['name' => 'billing_bill_billCity', 'type' => 'string', 'internal' => 'billCity'], + 'billing_bill_billZip' => ['name' => 'billing_bill_billZip', 'type' => 'string', 'internal' => 'billZip'], + 'billing_bill_billCountry' => ['name' => 'billing_bill_billCountry', 'type' => 'string', 'internal' => 'billCountry'], + 'billing_bill_gross' => ['name' => 'billing_bill_gross', 'type' => 'Serializable', 'internal' => 'gross'], + 'billing_bill_net' => ['name' => 'billing_bill_net', 'type' => 'Serializable', 'internal' => 'net'], + 'billing_bill_costs' => ['name' => 'billing_bill_costs', 'type' => 'Serializable', 'internal' => 'costs'], + 'billing_bill_profit' => ['name' => 'billing_bill_profit', 'type' => 'Serializable', 'internal' => 'profit'], + 'billing_bill_currency' => ['name' => 'billing_bill_currency', 'type' => 'int', 'internal' => 'currency'], + 'billing_bill_referral' => ['name' => 'billing_bill_referral', 'type' => 'int', 'internal' => 'referral'], + 'billing_bill_referral_name' => ['name' => 'billing_bill_referral_name', 'type' => 'string', 'internal' => 'referralName'], + 'billing_bill_reference' => ['name' => 'billing_bill_reference', 'type' => 'int', 'internal' => 'reference'], + 'billing_bill_payment' => ['name' => 'billing_bill_payment', 'type' => 'int', 'internal' => 'payment'], + 'billing_bill_payment_text' => ['name' => 'billing_bill_payment_text', 'type' => 'string', 'internal' => 'paymentText'], + 'billing_bill_paymentterms' => ['name' => 'billing_bill_paymentterms', 'type' => 'int', 'internal' => 'terms'], + 'billing_bill_paymentterms_text' => ['name' => 'billing_bill_paymentterms_text', 'type' => 'string', 'internal' => 'termsText'], + 'billing_bill_ship_type' => ['name' => 'billing_bill_ship_type', 'type' => 'int', 'internal' => 'shipping'], + 'billing_bill_ship_text' => ['name' => 'billing_bill_ship_text', 'type' => 'string', 'internal' => 'shippingText'], + 'billing_bill_client' => ['name' => 'billing_bill_client', 'type' => 'int', 'internal' => 'client'], + 'billing_bill_supplier' => ['name' => 'billing_bill_supplier', 'type' => 'int', 'internal' => 'supplier'], + 'billing_bill_created_by' => ['name' => 'billing_bill_created_by', 'type' => 'int', 'internal' => 'createdBy', '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 = [ 'elements' => [ 'mapper' => BillElementMapper::class, - 'table' => 'billing_out_element', - 'self' => 'billing_out_element_bill', + 'table' => 'billing_bill_element', + 'self' => 'billing_bill_element_bill', '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 = [ 'type' => [ 'mapper' => BillTypeMapper::class, - 'external' => 'billing_out_type', + 'external' => 'billing_bill_type', ], 'referral' => [ 'mapper' => AccountMapper::class, - 'external' => 'billing_out_referral', + 'external' => 'billing_bill_referral', ], ]; @@ -117,11 +126,15 @@ final class BillMapper extends DataMapperAbstract protected static array $belongsTo = [ 'createdBy' => [ 'mapper' => AccountMapper::class, - 'external' => 'billing_out_created_by', + 'external' => 'billing_bill_created_by', ], 'client' => [ '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 * @since 1.0.0 */ - protected static string $primaryField = 'billing_out_id'; + protected static string $primaryField = 'billing_bill_id'; /** * Primary table. @@ -139,18 +152,18 @@ final class BillMapper extends DataMapperAbstract * @var string * @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 { $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) ->leftJoin(BillElementMapper::getTable()) - ->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') - ->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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) ->execute() ->fetch(); @@ -160,11 +173,11 @@ final class BillMapper extends DataMapperAbstract public static function getSalesByClientId(int $id, \DateTime $start, \DateTime $end) : Money { $query = new Builder(self::$db); - $result = $query->select('SUM(billing_out_net)') + $result = $query->select('SUM(billing_bill_net)') ->from(self::$table) - ->where(self::$table . '.billing_out_client', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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(); @@ -174,13 +187,13 @@ final class BillMapper extends DataMapperAbstract public static function getAvgSalesPriceByItemId(int $id, \DateTime $start, \DateTime $end) : Money { $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) ->leftJoin(BillElementMapper::getTable()) - ->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') - ->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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) ->execute() ->fetch(); @@ -191,12 +204,12 @@ final class BillMapper extends DataMapperAbstract { // @todo: only delivers/invoice/production (no offers ...) $query = new Builder(self::$db); - $result = $query->select('billing_out_performance_date') + $result = $query->select('billing_bill_performance_date') ->from(self::$table) ->leftJoin(BillElementMapper::getTable()) - ->on(self::$table . '.billing_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') - ->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) - ->orderBy('billing_out_id', 'DESC') + ->on(self::$table . '.billing_bill_id', '=', BillElementMapper::getTable() . '.billing_bill_element_bill') + ->where(BillElementMapper::getTable() . '.billing_bill_element_item', '=', $id) + ->orderBy('billing_bill_id', 'DESC') ->limit(1) ->execute() ->fetch(); @@ -208,10 +221,10 @@ final class BillMapper extends DataMapperAbstract { // @todo: only delivers/invoice/production (no offers ...) $query = new Builder(self::$db); - $result = $query->select('billing_out_performance_date') + $result = $query->select('billing_bill_performance_date') ->from(self::$table) - ->where(self::$table . '.billing_out_client', '=', $id) - ->orderBy('billing_out_id', 'DESC') + ->where(self::$table . '.billing_bill_client', '=', $id) + ->orderBy('billing_bill_id', 'DESC') ->limit(1) ->execute() ->fetch(); @@ -235,8 +248,8 @@ final class BillMapper extends DataMapperAbstract $query ??= self::getQuery(null, [], RelationType::ALL, $depth); $query->leftJoin(BillElementMapper::getTable(), BillElementMapper::getTable() . '_' . $depth) - ->on(self::$table . '_' . $depth . '.billing_out_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_bill') - ->where(BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_item', '=', $id) + ->on(self::$table . '_' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_bill') + ->where(BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_item', '=', $id) ->limit($limit); 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? $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); if (!empty(self::$createdAt)) { @@ -272,14 +285,14 @@ final class BillMapper extends DataMapperAbstract $depth = 3; $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) - ->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) - ->on(self::$table . '_' . $depth . '.billing_out_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_bill') - ->where(BillElementMapper::getTable() . '_' . $depth . '.billing_out_element_item', '=', $id) - ->andWhere(self::$table . '_' . $depth . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '_' . $depth . '.billing_out_performance_date', '<=', $end) + ->on(self::$table . '_' . $depth . '.billing_bill_id', '=', BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_bill') + ->where(BillElementMapper::getTable() . '_' . $depth . '.billing_bill_element_item', '=', $id) + ->andWhere(self::$table . '_' . $depth . '.billing_bill_performance_date', '>=', $start) + ->andWhere(self::$table . '_' . $depth . '.billing_bill_performance_date', '<=', $end) ->orderBy('net_sales', 'DESC') ->limit($limit) ->groupBy(ClientMapper::getTable() . '_' . $depth . '.clientmgmt_client_id'); @@ -294,15 +307,15 @@ final class BillMapper extends DataMapperAbstract { $query = new Builder(self::$db); $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) ->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()) - ->on(self::$table . '.billing_out_billCountry', '=', CountryMapper::getTable() . '.country_code2') - ->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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') ->execute() ->fetchAll(\PDO::FETCH_KEY_PAIR); @@ -314,15 +327,15 @@ final class BillMapper extends DataMapperAbstract { $query = new Builder(self::$db); $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) ->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()) - ->on(self::$table . '.billing_out_billCountry', '=', CountryMapper::getTable() . '.country_code2') - ->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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') ->orderBy('net_sales', 'DESC') ->limit($limit) @@ -335,16 +348,16 @@ final class BillMapper extends DataMapperAbstract public static function getItemMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array { $query = new Builder(self::$db); - $result = $query->selectAs('SUM(billing_out_element_total_salesprice_net)', 'net_sales') - ->selectAs('SUM(billing_out_element_total_purchaseprice_net)', 'net_costs') - ->selectAs('YEAR(billing_out_performance_date)', 'year') - ->selectAs('MONTH(billing_out_performance_date)', 'month') + $result = $query->selectAs('SUM(billing_bill_element_total_salesprice_net)', 'net_sales') + ->selectAs('SUM(billing_bill_element_total_purchaseprice_net)', '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_out_id', '=', BillElementMapper::getTable() . '.billing_out_element_bill') - ->where(BillElementMapper::getTable() . '.billing_out_element_item', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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) ->groupBy('year', 'month') ->orderBy(['year', 'month'], ['ASC', 'ASC']) ->execute() @@ -356,14 +369,14 @@ final class BillMapper extends DataMapperAbstract public static function getClientMonthlySalesCosts(int $id, \DateTime $start, \DateTime $end) : array { $query = new Builder(self::$db); - $result = $query->selectAs('SUM(billing_out_net)', 'net_sales') - ->selectAs('SUM(billing_out_costs)', 'net_costs') - ->selectAs('YEAR(billing_out_performance_date)', 'year') - ->selectAs('MONTH(billing_out_performance_date)', 'month') + $result = $query->selectAs('SUM(billing_bill_net)', 'net_sales') + ->selectAs('SUM(billing_bill_costs)', 'net_costs') + ->selectAs('YEAR(billing_bill_performance_date)', 'year') + ->selectAs('MONTH(billing_bill_performance_date)', 'month') ->from(self::$table) - ->where(self::$table . '.billing_out_client', '=', $id) - ->andWhere(self::$table . '.billing_out_performance_date', '>=', $start) - ->andWhere(self::$table . '.billing_out_performance_date', '<=', $end) + ->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() diff --git a/Models/BillStatus.php b/Models/BillStatus.php old mode 100644 new mode 100755 diff --git a/Models/BillTransferType.php b/Models/BillTransferType.php new file mode 100644 index 0000000..929ef73 --- /dev/null +++ b/Models/BillTransferType.php @@ -0,0 +1,34 @@ + ['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'], ]; /** diff --git a/Models/NullBill.php b/Models/NullBill.php old mode 100644 new mode 100755 diff --git a/Models/NullBillType.php b/Models/NullBillType.php old mode 100644 new mode 100755 diff --git a/Models/PermissionState.php b/Models/PermissionState.php old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/invoice-archive.tpl.php b/Theme/Backend/invoice-archive.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/invoice-create.tpl.php b/Theme/Backend/invoice-create.tpl.php old mode 100644 new mode 100755 index 1552790..0e155ac --- a/Theme/Backend/invoice-create.tpl.php +++ b/Theme/Backend/invoice-create.tpl.php @@ -258,8 +258,8 @@ echo $this->getData('nav')->render(); ?> printHtml($this->request->getOrigin()); ?> - printHtml($this->request->getHeader()->getAccount()); ?> - printHtml($this->request->getHeader()->getAccount()); ?> + printHtml((string) $this->request->header->account); ?> + printHtml((string) $this->request->header->account); ?> Create Invoice printHtml((new \DateTime('now'))->format('Y-m-d H:i:s')); ?> diff --git a/Theme/Backend/purchase-invoice-list.tpl.php b/Theme/Backend/purchase-invoice-list.tpl.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/sales-bill-list.tpl.php b/Theme/Backend/sales-bill-list.tpl.php old mode 100644 new mode 100755 index 15c2f8d..7e3f8f3 --- a/Theme/Backend/sales-bill-list.tpl.php +++ b/Theme/Backend/sales-bill-list.tpl.php @@ -46,11 +46,11 @@ echo $this->getData('nav')->render(); ?> getNumber(); ?> type->getL11n(); ?> client->number; ?> - printHtml($value->client->profile->account->name3 . ' ' . $value->client->profile->account->name2 . ' ' . $value->client->profile->account->name1); ?> - client->mainAddress->address; ?> - client->mainAddress->postal; ?> - client->mainAddress->city; ?> - client->mainAddress->getCountry(); ?> + printHtml($value->billTo); ?> + billAddress; ?> + billZip; ?> + billCity; ?> + billCountry; ?> net->getCurrency(); ?> gross->getCurrency(); ?> profit->getCurrency(); ?> diff --git a/Theme/Backend/sales-bill.tpl.php b/Theme/Backend/sales-bill.tpl.php old mode 100644 new mode 100755 index fa6ec27..a45783f --- a/Theme/Backend/sales-bill.tpl.php +++ b/Theme/Backend/sales-bill.tpl.php @@ -12,6 +12,8 @@ */ declare(strict_types=1); +use phpOMS\Uri\UriFactory; + /** * @var \phpOMS\Views\View $this */ @@ -19,6 +21,8 @@ declare(strict_types=1); $bill = $this->getData('bill'); $elements = $bill->getElements(); +$billPdf = $bill->getMediaByType('bill'); + echo $this->getData('nav')->render(); ?>
@@ -185,6 +189,15 @@ echo $this->getData('nav')->render(); ?>
+
+
+
+
+ +
+
+
+
diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/composer.lock b/composer.lock old mode 100644 new mode 100755 diff --git a/info.json b/info.json old mode 100644 new mode 100755 index 3e81af5..16374bc --- a/info.json +++ b/info.json @@ -19,6 +19,7 @@ "dependencies": { "Admin": "1.0.0", "Sales": "1.0.0", + "Media": "1.0.0", "ClientManagement": "1.0.0" }, "providing": { diff --git a/tests/Autoloader.php b/tests/Autoloader.php old mode 100644 new mode 100755 diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php old mode 100644 new mode 100755 diff --git a/tests/phpunit_default.xml b/tests/phpunit_default.xml old mode 100644 new mode 100755