panel($idProject, $idCompany); $this->execPostTasks(); if (1 != V::get('_print', '', $_GET)) { UI::startContainer(['style'=>'text-align:right']); UI::link('link', " Drukuj", Request::getPathUri() . "index.php?_route=UrlAction_ProjektyOfertaAdminKosztorys&ID_COMPANY={$idCompany}&_print=1"); UI::endContainer(); } $this->defaultOferta($idCompany);// TODO: $idCompany } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function additionalPanel($idProject, $idCompany = 0) { UI::startTag('div', ['class'=>'container', 'style'=>'margin-top:1em']); UI::startTag('form', ['action'=>"", 'method'=>'get', 'class'=>'form-inline']); UI::startTag('div', ['class'=>"form-group"]); UI::emptyTag('input', ['type'=>"hidden", 'name'=>"_route", 'value'=>"UrlAction_ProjektyOfertaAdminKosztorys"]); UI::tag('label', ['for'=>'ID_COMPANY', 'style'=>'margin-right:1em'], "Nr kontrahenta (0 = cennik główny)"); UI::emptyTag('input', ['type'=>"text", 'name'=>"ID_COMPANY", 'value'=>$idCompany, 'class'=>'form-control', 'style'=>'margin-right:1em']);// TODO: Typespecial for Companies UI::emptyTag('input', ['type'=>"submit", 'value'=>"Wybierz", 'class'=>'btn btn-primary']); UI::endTag('div');// .form-group UI::endTag('form'); UI::endTag('div');// .container } public function ofertaAdminAction() { // TODO: check if user is allowed to run this action UI::gora(); UI::menu(); try { $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int'); $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int'); $admin = true; $ofertaArgs = compact('idProject', 'idCompany', 'admin'); $this->panel($idProject, $idCompany); if ($idProject > 0) { $this->oferta($ofertaArgs); } else { $this->defaultOferta(); } } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function ofertaCompanyAction() { // TODO: check if user is allowed to run this action UI::gora(); UI::menu(); try { $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int'); $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int');// TODO: $idCompany from ADMIN_USERS $admin = false; $companyAdmin = true; $ofertaArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin'); $this->panel($idProject, $idCompany); if ($idProject > 0) { $this->oferta($ofertaArgs); } else { $this->defaultOferta(); } } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function ofertaDefaultAdminAction() { // TODO: check if user is allowed to run this action UI::gora(); UI::menu(); try { $idProject = 0; $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int'); $this->panel($idProject, $idCompany); $this->defaultOferta(); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function ofertaAction() { // TODO: check if user is allowed to run this action UI::gora(); UI::menu(); try { $idProject = V::get('ID_PROJECT', 0, $_REQUEST, 'int'); $idCompany = V::get('ID_COMPANY', 0, $_REQUEST, 'int'); $admin = false; if (!$idProject) throw new Exception("Wrong param in 'ID_PROJECT' - expected integer!");// TODO: show select box if not defined $ofertaArgs = compact('idProject', 'idCompany', 'admin'); $this->panel($idProject, $idCompany); $this->oferta($ofertaArgs); } catch (Exception $e) { UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage()); } UI::dol(); } public function saveOffer($idProject, $idCompany, $args, $admin = false) { DBG::_('DBG', '>1', "args", $args, __CLASS__, __FUNCTION__, __LINE__); if (!$admin) return; $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany); DBG::_('DBG', '>1', "cennik", $cennik, __CLASS__, __FUNCTION__, __LINE__); $pdo = DB::getPDO(); { $add_id_zasob = 0; $add_unit = ''; $add_price = 0; $add_quantity = 0; $add__sth = $pdo->prepare(" insert into CRM_LISTA_ZASOBOW_OFFERS ( CRM_LISTA_ZASOBOW_ID , COMPANIES_ID , ID_PROJECT , OFFER_PRICE_PER_RESOURCE_UNIT , RESOURCE_UNIT_TYPE , OFFER_UNIT_TYPE , REQUIRED_RESOURCE_UNITS , A_RECORD_CREATE_AUTHOR , A_RECORD_CREATE_DATE ) values ( :id_zasob , :id_company , :id_project , :price , :unit , :unit , :quantity , :author , NOW() ) "); $add__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR); $add__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT); $add__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT); $add__sth->bindValue(':quantity', $add_quantity, PDO::PARAM_STR); $add__sth->bindParam(':id_zasob', $add_id_zasob, PDO::PARAM_INT); $add__sth->bindParam(':price', $add_price, PDO::PARAM_STR); $add__sth->bindParam(':unit', $add_unit, PDO::PARAM_STR); } { $edit_id_company = $idCompany; $edit_id_zasob = 0; $edit_unit = ''; $edit_price = 0; $edit_author = 0; $edit_quantity = 0; $edit__sth = $pdo->prepare(" update CRM_LISTA_ZASOBOW_OFFERS set CRM_LISTA_ZASOBOW_ID = :id_zasob , COMPANIES_ID = :id_company , ID_PROJECT = :id_project , OFFER_PRICE_PER_RESOURCE_UNIT = :price , RESOURCE_UNIT_TYPE = :unit , OFFER_UNIT_TYPE = :unit , REQUIRED_RESOURCE_UNITS = :quantity , A_RECORD_UPDATE_AUTHOR = :author , A_RECORD_UPDATE_DATE = NOW() where ID = :id "); $edit__sth->bindParam(':id', $edit_id, PDO::PARAM_INT); $edit__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR); $edit__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT); $edit__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT); $edit__sth->bindValue(':quantity', $edit_quantity, PDO::PARAM_STR); $edit__sth->bindParam(':id_zasob', $edit_id_zasob, PDO::PARAM_INT); $edit__sth->bindParam(':price', $edit_price, PDO::PARAM_STR); $edit__sth->bindParam(':unit', $edit_unit, PDO::PARAM_STR); } $schema = ProjectKosztorysSchema::getSchema(); foreach ($schema['config']['layer'] as $idLayer => $layData) { DBG::_('DBG', '>1', "layData", $layData, __CLASS__, __FUNCTION__, __LINE__); foreach ($layData['type'] as $idType => $typeLabel) { $edit_id = V::get("edit_price_id_{$idType}", '', $args); $add_price = V::get("price_{$idType}", '', $args); DBG::_('DBG', '>1', "typeLabel (edit={$edit_id}, price={$add_price})", $typeLabel, __CLASS__, __FUNCTION__, __LINE__); if ($edit_id > 0) { $edit_price = V::get("price_{$idType}", '', $args); $edit_price = str_replace(',', '.', $edit_price); if ($edit_id > 0 && $edit_price > 0) { $edit_id_zasob = $idType; $edit_unit = $layData['jednostka']; // TODO: check if anything change DBG::_('DBG', '>1', "EDIT price for idZasob({$idType}) {price:{$edit_price}, id_offer:{$edit_id}}", $typeLabel, __CLASS__, __FUNCTION__, __LINE__); $edit__sth->execute(); // TODO: add to hist } } else { $add_price = V::get("price_{$idType}", '', $args); $add_price = str_replace(',', '.', $add_price); if ($add_price > 0) { $add_id_zasob = $idType; $add_unit = $layData['jednostka']; DBG::_('DBG', '>1', "ADD price for idZasob({$idType}) {price:{$add_price}}", $typeLabel, __CLASS__, __FUNCTION__, __LINE__); $add__sth->execute(); } } } } } public function saveDefaultOffer($args) { DBG::_('DBG', '>1', "args", $args, __CLASS__, __FUNCTION__, __LINE__); $cennik = ProjectKosztorysCennik::getDefaultCennik(); DBG::_('DBG', '>1', "cennik", $cennik, __CLASS__, __FUNCTION__, __LINE__); $idCompany = 0; $idProject = 0; $pdo = DB::getPDO(); { $add_id_zasob = 0; $add_unit = ''; $add_price = 0; $add_quantity = 0; $add__sth = $pdo->prepare(" insert into CRM_LISTA_ZASOBOW_OFFERS ( CRM_LISTA_ZASOBOW_ID , COMPANIES_ID , ID_PROJECT , OFFER_PRICE_PER_RESOURCE_UNIT , RESOURCE_UNIT_TYPE , OFFER_UNIT_TYPE , REQUIRED_RESOURCE_UNITS , A_RECORD_CREATE_AUTHOR , A_RECORD_CREATE_DATE ) values ( :id_zasob , :id_company , :id_project , :price , :unit , :unit , :quantity , :author , NOW() ) "); $add__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR); $add__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT); $add__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT); $add__sth->bindValue(':quantity', $add_quantity, PDO::PARAM_STR); $add__sth->bindParam(':id_zasob', $add_id_zasob, PDO::PARAM_INT); $add__sth->bindParam(':price', $add_price, PDO::PARAM_STR); $add__sth->bindParam(':unit', $add_unit, PDO::PARAM_STR); } { $edit_id_zasob = 0; $edit_unit = ''; $edit_price = 0; $edit_author = 0; $edit_quantity = 0; $edit__sth = $pdo->prepare(" update CRM_LISTA_ZASOBOW_OFFERS set CRM_LISTA_ZASOBOW_ID = :id_zasob , COMPANIES_ID = :id_company , ID_PROJECT = :id_project , OFFER_PRICE_PER_RESOURCE_UNIT = :price , RESOURCE_UNIT_TYPE = :unit , OFFER_UNIT_TYPE = :unit , REQUIRED_RESOURCE_UNITS = :quantity , A_RECORD_UPDATE_AUTHOR = :author , A_RECORD_UPDATE_DATE = NOW() where ID = :id "); $edit__sth->bindParam(':id', $edit_id, PDO::PARAM_INT); $edit__sth->bindValue(':author', User::getLogin(), PDO::PARAM_STR); $edit__sth->bindValue(':id_project', $idProject, PDO::PARAM_INT); $edit__sth->bindValue(':id_company', $idCompany, PDO::PARAM_INT); $edit__sth->bindValue(':quantity', $edit_quantity, PDO::PARAM_STR); $edit__sth->bindParam(':id_zasob', $edit_id_zasob, PDO::PARAM_INT); $edit__sth->bindParam(':price', $edit_price, PDO::PARAM_STR); $edit__sth->bindParam(':unit', $edit_unit, PDO::PARAM_STR); } $schema = ProjectKosztorysSchema::getSchema(); foreach ($schema['config']['layer'] as $idLayer => $layData) { DBG::_('DBG', '>1', "layData", $layData, __CLASS__, __FUNCTION__, __LINE__); foreach ($layData['type'] as $idType => $typeLabel) { DBG::_('DBG', '>1', "typeLabel", $typeLabel, __CLASS__, __FUNCTION__, __LINE__); $edit_id = V::get("edit_price_id_{$idType}", '', $args); if ($edit_id > 0) { $edit_price = V::get("price_{$idType}", '', $args); $edit_price = str_replace(',', '.', $edit_price); if ($edit_id > 0 && $edit_price > 0) { $edit_id_zasob = $idType; $edit_unit = $layData['jednostka']; // TODO: check if anything change $edit__sth->execute(); // TODO: add to hist } } else { $add_price = V::get("price_{$idType}", '', $args); $add_price = str_replace(',', '.', $add_price); if ($add_price > 0) { $add_id_zasob = $idType; $add_unit = $layData['jednostka']; $add__sth->execute(); } } } } } public function defaultOferta($idCompany = 0) { $priceEditJs = (1 != V::get('_print', '', $_GET)) ? Request::getPathUri() . "index.php?_route=UrlAction_ProjektyOfertaAdminKosztorys&_task=updateAdminOfertaAjax&idCompany={$idCompany}" : false; $schema = ProjectKosztorysSchema::getSchema(); if (empty($schema['config']['type'])) throw new Exception("Schema error - brak zdefiniowanych typów"); $defCennik = ProjectKosztorysCennik::getDefaultCennik(); $cennik = ProjectKosztorysCennik::getDefaultCennik($idCompany); $workCennik = ProjectKosztorysCennik::getWorkCennik($idProject = 0, $idCompany); DBG::_('DBG', '>1', "defCennik", $defCennik, __CLASS__, __FUNCTION__, __LINE__); DBG::_('DBG', '>1', "cennik", $cennik, __CLASS__, __FUNCTION__, __LINE__); DBG::_('DBG', '>1', "workCennik", $workCennik, __CLASS__, __FUNCTION__, __LINE__); $title = "Cennik domyślny " . ($idCompany ? "firmy [{$idCompany}]" : '') . " dla Kosztorysów"; UI::setTitleJsTag($title); ?>

$layData) : ?> $typeLabel) : ?>
id zasobu typ jednostka miary cena jednostkowa 0) : ?> cena jedn. (robocizna)
onClick="return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateAdminOferta', { href: '' })" class="type_price-" style="padding:3px 6px; text-align:right"> onClick="return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Kosztorys:updateAdminOferta', { href: '' })" style="padding:3px 6px; text-align:right">
$layData) { if (array_key_exists($idType, $layData['type'])) $jednostka = $layData['jednostka']; } } if (DBG::isActive()) $response['_unit'] = $jednostka; $reqJson = Request::getRequestJson(); if (!empty($reqJson)) { if (!array_key_exists('price', $reqJson)) throw new Exception("Missing param price"); $price = V::get('price', 0, $reqJson, 'float'); ProjectKosztorysCennik::updatePriceDefaultCennik($idType, $idCompany, $price, $jednostka); } $response['id'] = $idType; $response['unitType'] = $unitType; $response['label'] = ProjectKosztorysCennik::getTypeLabel($idType); $response['defaultPrice'] = ProjectKosztorysCennik::getPriceDefaultCennik($idType, 0, $jednostka); $response['price'] = ProjectKosztorysCennik::getPrice($idType, $idProject = 0, $idCompany, $jednostka); $response['msg'] = ""; $response['type'] = "success"; return $response; } public function oferta($args) { $idProject = $args['idProject']; $idCompany = V::get('idCompany', 0, $args); $admin = V::get('admin', false, $args); $companyAdmin = V::get('companyAdmin', false, $args); if ($admin && '1' == V::get('save_offer', '', $_POST)) { $this->saveOffer($idProject, $idCompany, $_POST, $admin); } $defCennik = ProjectKosztorysCennik::getDefaultCennik($idCompany); $cennik = ProjectKosztorysCennik::getCennik($idProject, $idCompany); $viewLayerDataArgs = compact('idProject', 'idCompany', 'admin', 'companyAdmin'); UI::setTitleJsTag("Oferta " . (($idProject)? " [{$idProject}] " : '') . (($idCompany)? " Kontrahent({$idCompany})" : '') . " - Kosztorysy"); ?>
viewLayersData($viewLayerDataArgs); ?>