| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- Lib::loadClass('ProjectKosztorysSchema');
- class ProjectKosztorysCennik {
- /**
- * @returns [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
- */
- public static function getCennik($idProject, $idCompany = 0) {
- $schema = ProjectKosztorysSchema::getSchema();
- $typeIdList = array_keys($schema['config']['type']);
- $sqlTypeIdList = implode(',', $typeIdList);
- $pdo = DB::getPDO();
- $sth = $pdo->prepare("
- select o.ID
- , o.CRM_LISTA_ZASOBOW_ID as id_zasob
- , o.COMPANIES_ID as id_company
- , o.ID_PROJECT as id_project
- , o.OFFER_PRICE_PER_RESOURCE_UNIT as price
- , o.RESOURCE_UNIT_TYPE as unit
- -- , o.OFFER_UNIT_TYPE as unit
- , o.REQUIRED_RESOURCE_UNITS as quantity
- from CRM_LISTA_ZASOBOW_OFFERS o
- where o.CRM_LISTA_ZASOBOW_ID in({$sqlTypeIdList})
- -- and o.A_STATUS not in ('DELETED')
- and o.ID_PROJECT = :id_project
- and o.COMPANIES_ID = :id_company
- and o.RESOURCE_UNIT_TYPE != 'ROBOCIZNA'
- ");
- $sth->bindValue(':id_project', $idProject, PDO::PARAM_INT);
- $sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
- $sth->execute();
- $cennikRaw = $sth->fetchAll();
- $cennik = array();
- foreach ($cennikRaw as $itemRaw) {
- $item = $itemRaw;
- $item['price'] = round($item['price'], 2);
- $cennik[$itemRaw['id_zasob']] = $item;
- }
- return $cennik;
- }
- /**
- * @returns [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
- */
- public static function getWorkCennik($idProject, $idCompany = 0) {
- $schema = ProjectKosztorysSchema::getSchema();
- $typeIdList = array_keys($schema['config']['type']);
- $sqlTypeIdList = implode(',', $typeIdList);
- $pdo = DB::getPDO();
- $sth = $pdo->prepare("
- select o.ID
- , o.CRM_LISTA_ZASOBOW_ID as id_zasob
- , o.COMPANIES_ID as id_company
- , o.ID_PROJECT as id_project
- , o.OFFER_PRICE_PER_RESOURCE_UNIT as price
- , o.RESOURCE_UNIT_TYPE as unit
- -- , o.OFFER_UNIT_TYPE as unit
- , o.REQUIRED_RESOURCE_UNITS as quantity
- from CRM_LISTA_ZASOBOW_OFFERS o
- where o.CRM_LISTA_ZASOBOW_ID in({$sqlTypeIdList})
- -- and o.A_STATUS not in ('DELETED')
- and o.ID_PROJECT = :id_project
- and o.COMPANIES_ID = :id_company
- and o.RESOURCE_UNIT_TYPE = 'ROBOCIZNA'
- ");
- $sth->bindValue(':id_project', $idProject, PDO::PARAM_INT);
- $sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
- $sth->execute();
- $robociznaCennikRaw = $sth->fetchAll();
- $robociznaCennik = array();
- foreach ($robociznaCennikRaw as $itemRaw) {
- $item = $itemRaw;
- $item['price'] = round($item['price'], 2);
- $robociznaCennik[$itemRaw['id_zasob']] = $item;
- }
- return $robociznaCennik;
- }
- /**
- * @returns [ $id_zasob => [ 'price' => $price, 'ID', 'id_zasob', 'id_company', 'id_project', 'unit', 'quantity' ] ]
- */
- public static function getDefaultCennik($idCompany = 0) {
- $schema = ProjectKosztorysSchema::getSchema();
- $typeIdList = array_keys($schema['config']['type']);
- $sqlTypeIdList = implode(',', $typeIdList);
- $pdo = DB::getPDO();
- $sth = $pdo->prepare("
- select o.ID
- , o.CRM_LISTA_ZASOBOW_ID as id_zasob
- , o.COMPANIES_ID as id_company
- , o.ID_PROJECT as id_project
- , o.OFFER_PRICE_PER_RESOURCE_UNIT as price
- , o.RESOURCE_UNIT_TYPE as unit
- -- , o.OFFER_UNIT_TYPE as unit
- , o.REQUIRED_RESOURCE_UNITS as quantity
- from CRM_LISTA_ZASOBOW_OFFERS o
- where o.CRM_LISTA_ZASOBOW_ID in({$sqlTypeIdList})
- -- and o.A_STATUS not in ('DELETED')
- and o.ID_PROJECT = 0
- and o.COMPANIES_ID = :id_company
- ");
- $sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT);
- $sth->execute();
- $cennikRaw = $sth->fetchAll();
- $cennik = array();
- foreach ($cennikRaw as $itemRaw) {
- $item = $itemRaw;
- $item['price'] = round($item['price'], 2);
- if (!empty($cennik[$itemRaw['id_zasob']])) {
- if ($itemRaw['ID'] < $cennik[$itemRaw['id_zasob']]['ID']) continue;
- }
- $cennik[$item['id_zasob']] = $item;
- }
- return $cennik;
- }
- }
|