diff --git a/Admin/Installer.php b/Admin/Installer.php index b626b62..3f2aaf8 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -102,9 +102,6 @@ final class Installer extends InstallerAbstract /** @var \Modules\WarehouseManagement\Controller\ApiStockTypeController $module */ $module = $app->moduleManager->getModuleInstance('WarehouseManagement', 'ApiStockType'); - // @todo allow multiple alternative stock templates - // @todo implement ordering of templates - foreach ($types as $type) { $response = new HttpResponse(); $request = new HttpRequest(); diff --git a/Models/Stock.php b/Models/Stock.php index 839dbf3..647559c 100755 --- a/Models/Stock.php +++ b/Models/Stock.php @@ -25,6 +25,11 @@ use phpOMS\Stdlib\Base\Address; * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 + * + * @todo Add attributes for stock + * This is important for things like warehousing cost ratio (Lagerkostensatz) + * HR + energy + insurance + interest rate + machinery (e.g. depreciation) + leasing + cleaning + * + security + maintenance + ... */ class Stock { diff --git a/Models/StockMapper.php b/Models/StockMapper.php index dd71bb5..47be062 100755 --- a/Models/StockMapper.php +++ b/Models/StockMapper.php @@ -16,8 +16,11 @@ namespace Modules\WarehouseManagement\Models; use Modules\Admin\Models\AddressMapper; use Modules\ClientManagement\Models\ClientMapper; +use Modules\ItemManagement\Models\Item; +use Modules\ItemManagement\Models\StockIdentifierType; use Modules\SupplierManagement\Models\SupplierMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\DataStorage\Database\Query\Builder; /** * WarehouseManagement mapper class. @@ -93,4 +96,72 @@ final class StockMapper extends DataMapperFactory * @since 1.0.0 */ public const PRIMARYFIELD = 'warehousemgmt_stock_id'; + + public static function getStockDistribution(array $items) : array + { + $dists = []; + $reserved = []; + $ordered = []; + + $itemIdsString = \implode(',', $items); + + // @todo only select sales stock. Therefore we need a place to define the sales stock(s) + $temp = StockDistributionMapper::getAll() + ->where('item', $items, 'IN') + ->execute(); + + foreach ($temp as $t) { + if (!isset($dists[$t->item])) { + $dists[$t->item] = []; + } + + // @todo These numbers might need adjustments for delivery notes/invoices depending on + // how we implement them in the warehouse management (maybe flag them in the transaction protocol as reserved?) + // also remember the SD issue where delivery notes can be technically still in stock -> stock value still belongs to company + // solution: "just" do a soft adjust of the available numbers?! but don't change the actual stock in the db + // the SD solution where actually delivered delivery notes can be adjusted after "archiving" will not be allowed + // to allow them to see what happened with such a delivery note maybe we can implement a view shows how many of the items are + // actually still outstanding. This shouldn't be anything special since we need importing of delivery notes anyways and marking + // old delivery note elements in a way to show which line items or even sub-line items got invoiced/returned etc. + $dists[$t->item][] = $t; + } + + $stockIdentifier = StockIdentifierType::NONE; + + $sql = <<raw($sql)->execute()->fetchAll(\PDO::FETCH_ASSOC); + + foreach ($results as $result) { + if (!isset($reserved[(int) $result['billing_bill_element_item']])) { + $reserved[(int) $result['billing_bill_element_item']] = 0; + $ordered[(int) $result['billing_bill_element_item']] = 0; + } + + if ($result['billing_type_name'] === 'sales_order_confirmation') { + $reserved[(int) $result['billing_bill_element_item']] += (int) $result['quantity']; + } else { + $ordered[(int) $result['billing_bill_element_item']] += (int) $result['quantity']; + } + } + + return [ + 'dists' => $dists, + 'reserved' => $reserved, + 'ordered' => $ordered, + ]; + } }