mirror of
https://github.com/Karaka-Management/oms-WarehouseManagement.git
synced 2026-01-11 15:18:41 +00:00
update
This commit is contained in:
parent
cd18f753ca
commit
b957ef8136
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 = <<<SQL
|
||||
SELECT billing_bill_element.billing_bill_element_item,
|
||||
billing_type.billing_type_name,
|
||||
SUM(billing_bill_element.billing_bill_element_quantity) AS quantity
|
||||
FROM billing_bill_element
|
||||
LEFT JOIN itemmgmt_item ON billing_bill_element.billing_bill_element_item = itemmgmt_item.itemmgmt_item_id
|
||||
LEFT JOIN billing_bill ON billing_bill_element.billing_bill_element_bill = billing_bill.billing_bill_id
|
||||
LEFT JOIN billing_type ON billing_bill.billing_bill_type = billing_type.billing_type_id
|
||||
WHERE billing_bill_element.billing_bill_element_item IN ({$itemIdsString})
|
||||
AND itemmgmt_item.itemmgmt_item_stockidentifier != {$stockIdentifier}
|
||||
AND billing_type.billing_type_name IN ('sales_order_confirmation', 'purchase_order')
|
||||
GROUP BY billing_bill_element.billing_bill_element_item, billing_type.billing_type_name;
|
||||
SQL;
|
||||
|
||||
$query = new Builder(self::$db);
|
||||
$results = $query->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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user