| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('ProcesHelper');
- Lib::loadClass('Typespecial');
- class Route_DealsSales extends RouteBase {
- public function handleAuth() {
- if (!User::logged()) {
- throw new HttpException('Unauthorized', 401);
- }
- }
- public function defaultAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- $this->legacy_DEALS_SALES();
- SE_Layout::dol();
- }
- public function typespecialAction() {
- $DBG = ('1' == V::get('DBG', '', $_REQUEST));
- header("Content-type: application/json");
- $fld = V::get('fld', '', $_GET);
- switch ($fld) {
- case 'id_telboxes': {
- Lib::loadClass('TypespecialVariable');
- $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__DEALS_SALES_TELBOXES_NAME');
- $query = V::get('q', '', $_REQUEST);
- $rawRows = null;
- $rows = $typeSpecialTelboxes->getValuesWithExports($query);
- if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
- foreach ($rows as $kID => $vItem) {
- $itemJson = new stdClass();
- $itemJson->id = $vItem->id;
- $itemJson->name = $vItem->param_out;
- if (!empty($vItem->exports)) {
- $itemJson->exports = $vItem->exports;
- }
- $jsonData[] = $itemJson;
- }
- echo json_encode($jsonData);
- }
- break;
- case 'id_companies': {
- Lib::loadClass('TypespecialVariable');
- $typeSpecialCompanies = TypespecialVariable::getInstance(-1, '__COMPANIES');
- $query = V::get('q', '', $_REQUEST);
- $rawRows = null;
- $rows = $typeSpecialCompanies->getValuesWithExports($query);
- if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
- foreach ($rows as $kID => $vItem) {
- $itemJson = new stdClass();
- $itemJson->id = $vItem->id;
- $itemJson->name = $vItem->param_out;
- if (!empty($vItem->exports)) {
- $itemJson->exports = $vItem->exports;
- }
- $jsonData[] = $itemJson;
- }
- echo json_encode($jsonData);
- }
- break;
- }
- }
- public function getDataAjaxAction() {
- header("Content-type: application/json");
- $response = new stdClass();
- $response->msg = 'TODO: F. ' . __FUNCTION__ . ' L.' . __LINE__;
- echo json_encode($response);
- }
- public function inlineEditAjaxAction() {
- //header("Content-type: application/json");
- $response = new stdClass();
- $response->msg = 'TODO: F. ' . __FUNCTION__ . ' L.' . __LINE__;// TODO: DBG
- $response->_request = $_REQUEST;// TODO: DBG
- $year = V::get('year', 0, $_REQUEST, 'int');
- $month = V::get('month', 0, $_REQUEST, 'int');
- $telbox = V::get('telbox', '', $_REQUEST, 'word');
- if ($year <= 0) throw new Exception('Error: wrong year');
- if ($month <= 0 || $month > 12) throw new Exception('Error: wrong month');
- if (empty($telbox)) throw new Exception('Error: wrong telbox');
- $record = $this->_fetchSaleByParams($telbox, $year, $month);
- if (empty($record)) {
- return $this->_renderInlineCreateForm($telbox, $year, $month);
- } else {
- return $this->_renderInlineEditForm($record);
- }
- }
- public function saveInlineAjaxAction() {
- header("Content-type: application/json");
- $response = new stdClass();
- $response->msg = 'TODO: F. ' . __FUNCTION__ . ' L.' . __LINE__;
- $response->_request = $_REQUEST;// TODO: DBG
- $id = V::get('ID', 0, $_REQUEST, 'int');
- if ($id > 0) {
- return $this->_saveInlineEdit($id, $_REQUEST);
- } else {
- return $this->_saveInlineCreate($_REQUEST);
- }
- }
- private function _saveInlineEdit($id, $args) {
- $record = $this->_fetchSaleById($id);
- if (empty($record)) throw new HttpException("Record {$id} not exists", 404);
- DBG::_('DBG', '>2', "record", $record, __CLASS__, __FUNCTION__, __LINE__);// TODO: DBG
- DBG::_('DBG', '>2', "args", $args, __CLASS__, __FUNCTION__, __LINE__);// TODO: DBG
- $tblAcl = $this->_getTableAcl();
- $primaryKeyFieldName = 'ID';
- $primaryKey = V::get($primaryKeyFieldName, 0, $record);
- $itemPatch = new stdClass();
- $itemPatch->{$primaryKeyFieldName} = $primaryKey;
- $visibleCols = array('SALES_VALUE', 'marka', 'A_STATUS');
- foreach ($visibleCols as $fieldName) {
- $fieldID = $tblAcl->getFieldIdByName($fieldName);
- if (!$fieldID) throw new Exception("No field by name ({$fieldName})");
- if (!$tblAcl->isAllowed($fieldID, 'W', $record)) {
- throw new Exception("Brak uprawnień do zapisu ({$fieldName})");
- }
- $argsFieldName = "f{$fieldID}";
- if (!isset($args[$argsFieldName])) throw new Exception("Brak danych dla pola ({$fieldName})");
- $itemPatch->{$fieldName} = $args[$argsFieldName];
- }
- DBG::_('DBG', '>1', "TODO: save record", $itemPatch, __CLASS__, __FUNCTION__, __LINE__);// TODO: DBG
- $response = new stdClass();
- try {
- $affected = $tblAcl->updateItem($itemPatch);
- if ($affected > 0) {
- $response->type = 'success';
- $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
- } else if ($affected == 0) {
- $response->type = 'info';
- $response->msg = "Nie wprowadzono żadnych zmian";
- }
- $response->record = $tblAcl->getItem($primaryKey);
- }
- catch (Exception $e) {
- $response->type = 'error';
- $response->msg = $e->getMessage();
- }
- echo json_encode($response);
- }
- private function _saveInlineCreate($args) {
- $year = V::get('SALES_YEAR', 0, $args, 'int');
- $month = V::get('SALES_MONTH', 0, $args, 'int');
- $telbox = V::get('T_TELBOX_NEIGHBOUR_IN', '', $args, 'word');
- if ($year <= 0) throw new Exception('Error: wrong year');
- if ($month <= 0 || $month > 12) throw new Exception('Error: wrong month');
- if (empty($telbox)) throw new Exception('Error: wrong telbox');
- $tblAcl = $this->_getTableAcl();
- $primaryKeyFieldName = 'ID';
- $primaryKey = V::get($primaryKeyFieldName, 0, $record);
- $item = new stdClass();//$tblAcl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
- $item->T_TELBOX_NEIGHBOUR_IN = $telbox;
- $item->SALES_YEAR = $year;
- $item->SALES_MONTH = $month;
- $visibleCols = array('SALES_VALUE', 'marka');
- foreach ($visibleCols as $fieldName) {
- $fieldID = $tblAcl->getFieldIdByName($fieldName);
- if (!$fieldID) throw new Exception("No field by name ({$fieldName})");
- if (!$tblAcl->isAllowed($fieldID, 'C', $record)) {
- throw new Exception("Brak uprawnień do utworzenia ({$fieldName})");
- }
- $argsFieldName = "f{$fieldID}";
- if (!isset($args[$argsFieldName])) throw new Exception("Brak danych dla pola ({$fieldName})");
- $item->{$fieldName} = $args[$argsFieldName];
- }
- try {
- $createdId = $tblAcl->addItem($item);
- if ($createdId) {
- $response->type = 'success';
- $response->msg = "Utworzono pomyślnie rekord nr {$createdId}";
- $response->id = $createdId;
- $response->record = $tblAcl->getItem($createdId);
- }
- else {
- $response->type = 'error';
- $response->msg = "Nie udało się utworzyć nowego rekordu!";
- }
- }
- catch (Exception $e) {
- $response->type = 'error';
- $response->msg = "Wystąpiły błędy!";
- $response->msg = $e->getMessage();
- }
- echo json_encode($response);
- }
- private function _fetchSaleByParams($telbox, $year, $month) {
- $record = null;
- $db = DB::getDB();
- $sqlWhere = array();
- $sqlWhere[] = " o.`A_STATUS`!='DELETED' ";
- $sqlIdTelboxes = $db->_($telbox);
- $sqlWhere[] = " o.`T_TELBOX_NEIGHBOUR_IN`='{$sqlIdTelboxes}' ";
- $sqlWhere[] = " o.`SALES_YEAR`='{$year}' ";
- $sqlWhere[] = " o.`SALES_MONTH`='{$month}' ";
- $sqlWhere = (!empty($sqlWhere))? implode(" and ", $sqlWhere) : '';
- $sql = "select o.`ID`
- , o.`T_TELBOX_NEIGHBOUR_IN`
- , o.`ID_DEALS_TABLE`
- , o.`SALES_YEAR`
- , o.`SALES_MONTH`
- , o.`SALES_VALUE`
- , o.`marka`
- , o.`A_STATUS`
- from `DEALS_SALES` as o
- where
- {$sqlWhere}
- ";
- DBG::_('DBG_SQL', '>1', "sql:fetch({telbox:{$telbox},year:{$year},month:{$month}})", $sql, __CLASS__, __FUNCTION__, __LINE__);
- $res = $db->query($sql);
- while ($r = $db->fetch($res)) {
- $record = $r;
- }
- return $record;
- }
- private function _fetchSaleById($idSale) {
- $record = null;
- $db = DB::getDB();
- $sqlWhere = array();
- $sqlWhere[] = " o.`A_STATUS`!='DELETED' ";
- $sqlWhere[] = " o.`ID`='{$idSale}' ";
- $sqlWhere = (!empty($sqlWhere))? implode(" and ", $sqlWhere) : '';
- $sql = "select o.`ID`
- , o.`T_TELBOX_NEIGHBOUR_IN`
- , o.`ID_DEALS_TABLE`
- , o.`SALES_YEAR`
- , o.`SALES_MONTH`
- , o.`SALES_VALUE`
- , o.`marka`
- , o.`A_STATUS`
- from `DEALS_SALES` as o
- where
- {$sqlWhere}
- ";
- DBG::_('DBG_SQL', '>1', "sql:fetch({telbox:{$telbox},year:{$year},month:{$month}})", $sql, __CLASS__, __FUNCTION__, __LINE__);
- $res = $db->query($sql);
- while ($r = $db->fetch($res)) {
- $record = $r;
- }
- return $record;
- }
- private function _renderInlineCreateForm($telbox, $year, $month) {
- //DBG::_(true, true, "TODO: Edit Form for record", $record, __CLASS__, __FUNCTION__, __LINE__);// TODO: DBG
- $DBG = ('1' == V::get('DBG', '', $_REQUEST));
- header("Content-type: text/plain");
- $row = $record;// TODO: refactor
- $tblAcl = $this->_getTableAcl();
- $visibleCols = array('SALES_VALUE', 'marka');
- $hasTypeSpecial = false;
- foreach ($visibleCols as $fieldName) {
- $fieldID = $tblAcl->getFieldIdByName($fieldName);
- if (!$fieldID) throw new Exception("No field by name ({$fieldName})");
- $fieldVal = ($tblAcl->isAllowed($fieldID, 'R', $row))? V::get($fieldName, '', $row) : '*****';
- $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
- $vCol = $tblAcl->getField($fieldID);
- $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
- $tsValues = array();
- $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
- if ($typeSpecial) {
- if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
- $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
- if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
- if (!empty($specialValues)) {
- $tsValues[$row->ID] = implode('<br>', $specialValues);
- }
- }
- ?>
- <label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
- <strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
- <?php if (!empty($vCol['opis'])) : ?>
- <em><?php echo $vCol['opis']; ?></em>
- <?php $perms = $tblAcl->getFieldPerms($fieldID); SE_Layout::hotKeyDBG($perms); ?>
- <?php endif; ?>
- </label>
- <?php
- $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
- if (!empty($tsValues[$row->ID])) {
- $fieldParams['typespecialValue'] = $tsValues[$row->ID];
- }
- $vDefault = $tblAcl->getColDefault($fieldName);
- if (!empty($vDefault)) {
- $fieldParams['default'] = $vDefault;
- }
- echo $tblAcl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
- if ($typeSpecial) $hasTypeSpecial = true;
- }
- if ($hasTypeSpecial) {
- echo '<p style="padding:100px 0;"></p>';
- }
- ?>
- <input type="hidden" name="T_TELBOX_NEIGHBOUR_IN" value="<?php echo $telbox; ?>" />
- <input type="hidden" name="SALES_YEAR" value="<?php echo $year; ?>" />
- <input type="hidden" name="SALES_MONTH" value="<?php echo $month; ?>" />
- <?php
- exit;
- }
- private function _renderInlineEditForm($record) {
- //DBG::_(true, true, "TODO: Edit Form for record", $record, __CLASS__, __FUNCTION__, __LINE__);// TODO: DBG
- $DBG = ('1' == V::get('DBG', '', $_REQUEST));
- header("Content-type: text/plain");
- $row = $record;// TODO: refactor
- $tblAcl = $this->_getTableAcl();
- // TODO: $cols = array('T_TELBOX_NEIGHBOUR_IN','SALES_YEAR','SALES_MONTH','SALES_VALUE','marka');
- // TODO: form for only 'SALES_VALUE' and eventually 'marka'
- $visibleCols = array('SALES_VALUE', 'marka', 'A_STATUS');
- $hasTypeSpecial = false;
- foreach ($visibleCols as $fieldName) {
- $fieldID = $tblAcl->getFieldIdByName($fieldName);
- if (!$fieldID) throw new Exception("No field by name ({$fieldName})");
- $fieldVal = ($tblAcl->isAllowed($fieldID, 'R', $row))? V::get($fieldName, '', $row) : '*****';
- $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
- $vCol = $tblAcl->getField($fieldID);
- $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
- $tsValues = array();
- $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
- if ($typeSpecial) {
- $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
- if (!empty($specialValues)) {
- $tsValues[$row->ID] = implode('<br>', $specialValues);
- }
- }
- ?>
- <label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
- <strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
- <?php if (!empty($vCol['opis'])) : ?>
- <em><?php echo $vCol['opis']; ?></em>
- <?php $perms = $tblAcl->getFieldPerms($fieldID); SE_Layout::hotKeyDBG($perms); ?>
- <?php endif; ?>
- </label>
- <?php
- $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
- if (!empty($tsValues[$row->ID])) {
- $fieldParams['typespecialValue'] = $tsValues[$row->ID];
- }
- $vDefault = $tblAcl->getColDefault($fieldName);
- if (!empty($vDefault)) {
- $fieldParams['default'] = $vDefault;
- }
- echo $tblAcl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
- if ($typeSpecial) $hasTypeSpecial = true;
- }
- if ($hasTypeSpecial) {
- echo '<p style="padding:100px 0;"></p>';
- }
- ?>
- <input type="hidden" name="ID" value="<?php echo $record->ID; ?>" />
- <?php
- exit;
- }
- private function _getTableAcl() {
- $zasobObj = ProcesHelper::getZasobTableInfoByUri('default_db/deals_sales');
- if (!$zasobObj) throw new Exception("Zasob tabela deals_sales nie istnieje.");
- $userAcl = User::getAcl();
- $userAcl->fetchGroups();
- if (!$userAcl->hasTableAcl($zasobObj->ID)) throw new Exception("Brak uprawnień do tabeli ");
- $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
- return $tblAcl;
- }
- public function legacy_DEALS_SALES() {
- $id_telboxes = V::get('id_telboxes', '', $_REQUEST);
- $id_companies = V::get('id_companies', '', $_REQUEST, 'int');
- $idTelboxes = $id_telboxes;
- if (!empty($idTelboxes)) {
- if (!empty($idTelboxes)) {
- if (false !== strpos($idTelboxes, ': ')) {
- $parts = explode(': ', $idTelboxes, 2);
- $idTelboxes = $parts[0];
- }
- }
- }
- SE_Layout::menu();
- Lib::loadClass('TypespecialVariable');
- $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__DEALS_SALES_TELBOXES_NAME');
- $typeSpecialCompanies = null;// TypespecialVariable::getInstance(-1, '__COMPANIES');
- $obroty = array();
- $obrotyByYear = array();
- $marki = array();
- $obrotyToMarki = array();
- if (!empty($idTelboxes)) {
- $db = DB::getDB();
- $sqlWhere = array();
- $sqlWhere[] = " o.`A_STATUS`!='DELETED' ";
- $sqlIdTelboxes = $db->_($idTelboxes);
- $sqlWhere[] = " o.`T_TELBOX_NEIGHBOUR_IN`='{$sqlIdTelboxes}' ";
- $sqlWhere = (!empty($sqlWhere))? implode(" and ", $sqlWhere) : '';
- $sql = "select o.`ID`
- -- , d.`T_TELBOX_NEIGHBOUR_IN`
- , o.`T_TELBOX_NEIGHBOUR_IN`
- , o.`ID_DEALS_TABLE`
- -- , o.`SALES_DATE`
- , o.`SALES_YEAR`
- , o.`SALES_MONTH`
- , o.`SALES_VALUE`
- , o.`marka`
- from `DEALS_SALES` as o
- -- join `DEALS_TABLE` as d on (d.`ID`=o.`ID_DEALS_TABLE`)
- where
- {$sqlWhere}
- ";
- if(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
- $res = $db->query($sql);
- while ($r = $db->fetch($res)) {
- $year = $r->SALES_YEAR;
- $month = sprintf("%02d", $r->SALES_MONTH);
- $obroty[$r->ID_DEALS_TABLE][$year][$month] = $r->SALES_VALUE;
- $obrotyByYear[$year][$month] = floatval($r->SALES_VALUE);
- $marki[$r->marka] = true;
- $obrotyToMarki[$year][$month] = $r->marka;
- }
- }
- krsort($obrotyByYear);
- //DBG::_(true, true, "obrotyByYear", $obrotyByYear, __CLASS__, __FUNCTION__, __LINE__);
- //DBG::_('DBG', '>0', "marki", $marki, __CLASS__, __FUNCTION__, __LINE__);
- //DBG::_('DBG', '>0', "obrotyToMarki", $obrotyToMarki, __CLASS__, __FUNCTION__, __LINE__);
- $markiOut = array();
- {
- $markiLabels = array('primary', 'success', 'warning', 'danger', 'default');
- // <span class="label label-default">Default</span>
- reset($markiLabels);
- foreach ($marki as $marka => $vBool) {
- $markiOut[$marka] = current($markiLabels);
- if (!next($markiLabels)) reset($markiLabels);
- }
- }// Default Primary Success Info Warning Danger
- $monthsOut = array();
- for ($i = 0; $i < 12; $i++) $monthsOut[] = sprintf("%02d", $i + 1);
- $initData = new stdClass();
- $initData->obroty = $obrotyByYear;
- $initData->marki = $markiOut;
- $initData->obrotyToMarki = $obrotyToMarki;
- $initData->months = $monthsOut;
- $initData->years = array_keys($obrotyByYear);
- if (!empty($initData->years)) {
- $lastYear = date("Y", mktime(date('H'), date('i'), date('s'), date("m") + 3, date("d"), date("Y")));
- $firstYear = end($initData->years);
- if ($firstYear <= $lastYear) {
- $years = array();
- for ($i = $firstYear; $i <= $lastYear; $i++) {
- $years[] = $i;
- }
- $initData->years = array_reverse($years);
- }
- }
- //DBG::_(true, true, "initData", $initData, __CLASS__, __FUNCTION__, __LINE__);
- ?>
- <style type="text/css">
- .cell_marka_primary { background-color: #d9edf7; }
- .cell_marka_success { background-color: #dff0d8; }
- .cell_marka_warning { background-color: #fcf8e3; }
- .cell_marka_danger { background-color: #f2dede; }
- .cell_marka_default { background-color: #f5f5f5; }
- </style>
- <div class="container-fluid">
- <p></p>
- <form action="" method="GET" class="form-inline">
- <input type="hidden" name="_route" value="DealsSales">
- <table>
- <!--
- <summary>Wybierz lokal i/lub firmę w celu przeglądania obrotów </summary>
- -->
- <thead>
- <tr>
- <th style="text-align:left">Wyszukaj lokal lub markę</th>
- <th style="text-align:left">
- <?php if ($typeSpecialCompanies) : ?>
- Firma
- <?php endif; ?>
- </th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- <?php if ($typeSpecialTelboxes) : ?>
- <?php
- $fName = 'id_telboxes';
- $fldParams = array();
- $fldParams['allowCreate'] = false;
- $fldParams['ajaxDataUrlBase'] = "index.php?_route=DealsSales&_task=typespecial&fld={$fName}";
- //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
- echo $typeSpecialTelboxes->showFormItem($tblID = -1, $fName, $selValue = $id_telboxes, $fldParams);
- ?>
- <?php endif; ?>
- </td>
- <td>
- <?php if ($typeSpecialCompanies) : ?>
- <?php
- $fName = 'id_companies';
- $fldParams = array();
- $fldParams['allowCreate'] = false;
- $fldParams['ajaxDataUrlBase'] = "index.php?_route=DealsSales&_task=typespecial&fld={$fName}";
- //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
- echo $typeSpecialCompanies->showFormItem($tblID = -1, $fName, $selValue = $id_companies, $fldParams);
- ?>
- <?php endif; ?>
- </td>
- </tr>
- <tr>
- <td clspan="2">
- <button class="btn">wybierz</button>
- </td>
- </tr>
- </tbody>
- </table>
- </form>
- <?php if (empty($obroty)) : ?>
-
- <?php else : ?>
- <hr>
- <div id="dealsSalesByMonth"></div>
- <script>
- (function($, undefined) {
- var DealsSalesTable = function () {
- var priv = {};// private api
- var publ = {};// public api
- priv.options = {};
- var defaults = {
- url: '',
- urlInlineEdit: '',
- urlSaveInlineEdit: '',
- initData: {},
- debug: false
- },
- _uiNodeCont = null,// container node
- _uiNode$Table = null,
- _inlineEditBox$Node = null,
- _state = {};// state - to replace variables below (date, ...)
- priv.init = function () {
- _uiNodeCont = priv.options.id;
- _state = {};// init state
- priv.initEvents();
- priv.initData();
- priv.initialRender();// set up _uiNode$...
- };
- priv.initEvents = function () {
- jQuery(_uiNodeCont).on('DealsSalesTable:render', priv.onRender);
- };
- priv.initData = function () {
- if (!priv.options.initData) return;
- if (priv.options.initData.obroty) _state.obroty = priv.options.initData.obroty;
- if (priv.options.initData.marki) _state.marki = priv.options.initData.marki;
- if (priv.options.initData.obrotyToMarki) _state.obrotyToMarki = priv.options.initData.obrotyToMarki;
- if (priv.options.initData.months) _state.months = priv.options.initData.months;
- if (priv.options.initData.years) _state.years = priv.options.initData.years;
- if (priv.options.initData.fltrMarka) _state.fltrMarka = priv.options.initData.fltrMarka;
- };
- priv.initialRender = function () {
- _uiNode$Marki = $('<table class="table table-bordered" style="width:auto"></table>');
- $('<tbody><tr><th>Marki:</th></tr></tbody>').appendTo(_uiNode$Marki);
- _uiNode$Marki.appendTo(_uiNodeCont);
- _uiNode$Table = $('<table class="table table-bordered table-hover"></table>');
- {// thead
- var thead$Node = $('<thead></thead>').appendTo(_uiNode$Table);
- var theadTr$Node = $('<tr></tr>').appendTo(thead$Node);
- $('<th></th>').appendTo(theadTr$Node);
- $.each(_state.months, function(index, value) {
- $('<th>' + value + '</th>').appendTo(theadTr$Node);
- });
- $('<th>suma</th>').appendTo(theadTr$Node);
- }
- $('<tbody></tbody>').appendTo(_uiNode$Table);
- _uiNode$Table.appendTo(_uiNodeCont);
- _uiNode$GraphByYear = $('<div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto"></div>');
- $('<canvas id="wykres03" width="1760" height="300">[No canvas support]</canvas>').appendTo(_uiNode$GraphByYear);
- _uiNode$GraphByYear.appendTo(_uiNodeCont);
- _uiNode$GraphByMonth = $('<div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto"></div>');
- $('<canvas id="wykres04" width="1760" height="300">[No canvas support]</canvas>').appendTo(_uiNode$GraphByMonth);
- _uiNode$GraphByMonth.appendTo(_uiNodeCont);
- priv.renderHeaderMarki();
- priv.renderTableBody();
- priv.renderGraphByYear();
- priv.renderGraphByMonth();
- priv.renderInitInlineEditBox();// .dealsSales__inlineEditBox
- };
- priv.renderGraphByYear = function(record) {
- var jsonData = [],
- jsonLabels = [],
- jsonTooltips = [],
- jsonColors = ['Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)'],
- jsonColorsAll = [],
- wykresWidth = 940,
- wykresMinItemWidth = 15,
- graphGutterLeft = 60,
- graphGutterRight = 25,
- itemsInLabelCount = 0,
- currentNode = _uiNode$GraphByYear.children('canvas'),
- node = $('<canvas id="wykres03" width="1760" height="300">[No canvas support]</canvas>')
- ;
- {// replace node
- currentNode.replaceWith(node);
- }
- $.each(_state.obroty, function(kYear, vSalesByMonth) {
- var jsonYearData = {},
- yearDataValues = []
- ;
- jsonLabels.push(parseInt(kYear));
- $.each(_state.months, function(monthIdx, vMonth) {
- var isFilteredOutByMarka = false;
- if (_state.fltrMarka) {
- if (_state.fltrMarka != _state.obrotyToMarki[kYear][vMonth]) {
- isFilteredOutByMarka = true;
- }
- }
- if (undefined === vSalesByMonth[vMonth] || isFilteredOutByMarka) {
- jsonYearData['' + kYear + '-' + vMonth] = 0;
- } else {
- jsonYearData['' + kYear + '-' + vMonth] = vSalesByMonth[vMonth];
- }
- });
- $.each(jsonYearData, function(kLabel, vValue) {
- jsonTooltips.push('Obrót ' + numeral(vValue).format('0,0[.]00') + ' w ' + kLabel);
- });
- yearDataValues = Object.keys(jsonYearData).map(function (key) {
- return jsonYearData[key];
- });
- jsonData.push(yearDataValues);
- itemsInLabelCount = Math.max(itemsInLabelCount, yearDataValues.length);
- });
- {// colors
- for (var i = 0, mi = 0, mc = jsonColors.length; i < 12; i++) {
- jsonColorsAll.push(jsonColors[mi]);
- if (++mi >= mc) {
- mi = 0;
- }
- }
- jsonColors = jsonColorsAll;
- }
- {// wykres width
- wykresTestWidth = jsonLabels.length * (20 * 2 + itemsInLabelCount * wykresMinItemWidth) + graphGutterLeft + graphGutterRight;
- wykresWidth = Math.max(wykresWidth, wykresTestWidth);
- jQuery('#wykres03').css({width: wykresWidth});
- }
- var bar = new RGraph.Bar('wykres03', jsonData)
- .Set('labels', jsonLabels)
- .Set('colors', jsonColors)
- .Set('strokestyle', 'white')
- .Set('linewidth', 1)
- .Set('shadow', true)
- .Set('shadow.color', '#ccc')
- .Set('shadow.offsetx', 0)
- .Set('shadow.offsety', 0)
- .Set('shadow.blur', 10)
- .Set('gutter.bottom', 30)
- .Set('gutter.left', graphGutterLeft)
- .Set('gutter.right', graphGutterRight)
- .Set('tooltips', RGraph.ISOLD ? null : jsonTooltips)
- .Set('tooltips.event', 'mousemove')
- .Set('labels.above', true)
- .Set('hmargin', 20)
- .Draw();
- };
- priv.renderGraphByMonth = function(record) {
- var jsonData = [],
- jsonLabels = ['styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień'],
- jsonTooltips = [],
- jsonColors = ['Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)'],
- jsonColorsAll = [],
- wykresWidth = 940,
- wykresMinItemWidth = 15,
- graphGutterLeft = 60,
- graphGutterRight = 25,
- itemsInLabelCount = 0,
- currentNode = _uiNode$GraphByMonth.children('canvas'),
- node = $('<canvas id="wykres04" width="1760" height="300">[No canvas support]</canvas>')
- ;
- {// replace node
- currentNode.replaceWith(node);
- }
- $.each(_state.months, function(monthIdx, vMonth) {
- var jsonByMonthData = {},
- byMonthDataValues = []
- ;
- $.each(_state.obroty, function(kYear, vSalesByMonth) {
- var isFilteredOutByMarka = false;
- if (_state.fltrMarka) {
- if (_state.fltrMarka != _state.obrotyToMarki[kYear][vMonth]) {
- isFilteredOutByMarka = true;
- }
- }
- if (undefined === vSalesByMonth[vMonth] || isFilteredOutByMarka) {
- jsonByMonthData['' + kYear + '-' + vMonth] = 0;
- } else {
- jsonByMonthData['' + kYear + '-' + vMonth] = vSalesByMonth[vMonth];
- }
- });
- $.each(jsonByMonthData, function(kLabel, vValue) {
- jsonTooltips.push('Obrót ' + numeral(vValue).format('0,0[.]00') + ' w ' + kLabel);
- });
- byMonthDataValues = Object.keys(jsonByMonthData).map(function (key) {
- return jsonByMonthData[key];
- });
- jsonData.push(byMonthDataValues);
- itemsInLabelCount = Math.max(itemsInLabelCount, byMonthDataValues.length);
- });
- {// colors
- for (var i = 0, mi = 0, mc = jsonColors.length; i < 12; i++) {
- jsonColorsAll.push(jsonColors[mi]);
- if (++mi >= mc) {
- mi = 0;
- }
- }
- jsonColors = jsonColorsAll;
- }
- {// wykres width
- wykresTestWidth = jsonLabels.length * (20 * 2 + itemsInLabelCount * wykresMinItemWidth) + graphGutterLeft + graphGutterRight;
- wykresWidth = Math.max(wykresWidth, wykresTestWidth);
- jQuery('#wykres04').css({width: wykresWidth});
- }
- var bar = new RGraph.Bar('wykres04', jsonData)
- .Set('labels', jsonLabels)
- .Set('colors', jsonColors)
- .Set('strokestyle', 'white')
- .Set('linewidth', 1)
- .Set('shadow', true)
- .Set('shadow.color', '#ccc')
- .Set('shadow.offsetx', 0)
- .Set('shadow.offsety', 0)
- .Set('shadow.blur', 10)
- .Set('gutter.bottom', 30)
- .Set('gutter.left', graphGutterLeft)
- .Set('gutter.right', graphGutterRight)
- .Set('tooltips', RGraph.ISOLD ? null : jsonTooltips)
- .Set('tooltips.event', 'mousemove')
- .Set('labels.above', true)
- .Set('hmargin', 20)
- .Draw();
- };
- priv.renderHeaderMarki = function(record) {
- var currentNode = _uiNode$Marki.children('tbody').children('tr'),
- node = $('<tr></tr>'),
- marki = _state.marki,
- th$ = $('<th><i class="glyphicon glyphicon-filter"></i> Marki:</th>').appendTo(node);
- ;
- if (_state.fltrMarka) {
- rmFltrBtn = $('<i title="Pokaż wszystkie marki" class="glyphicon glyphicon-remove" style="cursor:pointer; color:red; opacity:0.4;"></i>');
- rmFltrBtn.on('click', priv.removeFltrMarka);
- rmFltrBtn.prependTo(th$);
- }
- $.each(_state.marki, function(markaLabel, markaClassName) {
- var isFiltered = (_state.fltrMarka == markaLabel),
- markaInput = '<input type="radio" title="Pokaż tylko markę ' + markaLabel + '" name="fltr_marka" value="' + markaLabel + '" ' + (isFiltered ? ' checked="checked"' : '') + '>',
- td$Node = $('<td>' + markaInput + ' <b>' + markaLabel + '</b></td>').appendTo(node)
- ;
- td$Node.addClass('cell_marka_' + markaClassName);
- td$Node.on('click', 'input', priv.filterMarka);
- });
- currentNode.replaceWith(node);
- };
- priv.removeFltrMarka = function(e) {
- _state.fltrMarka = null;
- jQuery(_uiNodeCont).trigger('DealsSalesTable:render', ['body','marki','graphs']);
- };
- priv.filterMarka = function(e) {
- var target$ = $(e.target),
- isChecked = target$.is(':checked');
- console.log('isChecked', isChecked, 'target$', target$, 'e', e);
- _state.fltrMarka = (isChecked)? target$.val() : null;
- jQuery(_uiNodeCont).trigger('DealsSalesTable:render', ['body','marki','graphs']);
- };
- priv.renderTableBody = function(record) {
- var currentNode = _uiNode$Table.children('tbody'),
- node = $('<tbody></tbody>'),
- vSalesByYear = _state.obroty
- ;
- $.each(_state.years, function(yearIdx, vYearId) {
- var vSalesByMonth = vSalesByYear[vYearId];
- var tr$Node = $('<tr></tr>').appendTo(node);
- $('<th>' + vYearId + '</th>').appendTo(tr$Node);
- var suma = 0;
- $.each(_state.months, function(monthsIdx, vMonth) {
- var td$Node = $('<td></td>').appendTo(tr$Node);
- td$Node.css({textAlign: 'right'});
- var saleValue = NaN;
- if (vSalesByMonth) {
- saleValue = parseFloat(vSalesByMonth[vMonth]);
- if (_state.fltrMarka) {
- if (_state.fltrMarka != _state.obrotyToMarki[vYearId][vMonth]) {
- saleValue = NaN;
- }
- }
- }
- if (isNaN(saleValue)) {
- td$Node.text('...');
- td$Node.css({color: '#ddd'});
- } else {
- suma += saleValue;
- $('<nobr>' + numeral(saleValue).format('0,0[.]00') + '</nobr>').appendTo(td$Node);
- if (undefined !== _state.obrotyToMarki[vYearId][vMonth]) {
- var marka = _state.obrotyToMarki[vYearId][vMonth];
- td$Node.addClass('cell_marka_' + _state.marki[marka]);
- }
- }
- td$Node.on('dblclick', {year:vYearId, month:vMonth}, priv.cellDblClicked);
- });
- var suma$Node = $('<td>' + numeral(suma).format('0,0[.]00') + '</td>').appendTo(tr$Node);
- suma$Node.css({textAlign: 'right'});
- });
- currentNode.replaceWith(node);
- };
- priv.renderInitInlineEditBox = function() {
- var nodeClass = 'dealsSales__inlineEditBox',
- node;
- var node = $('<div class="' + nodeClass + ' modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>');
- var modalWrap = $('<div class="modal-dialog"></div>').appendTo(node);
- var modalWrap = $('<div class="modal-content"></div>').appendTo(modalWrap);
- var frmInlineEdit = $('<form style="margin:0;padding:0;"></form>').appendTo(modalWrap);
- var iebHead = $('<div class="modal-header">').appendTo(frmInlineEdit);
- $('<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i></button>').appendTo(iebHead);
- $('<h3 id="myModalLabel">Edytuj</h3>').appendTo(iebHead);
- var iebBodyWrap = $('<div class="modal-body" style="padding:0"></div>').appendTo(frmInlineEdit);
- var iebBody = $('<div style="padding:15px"></div>').appendTo(iebBodyWrap);
- //$('<input type="hidden" name="ID" value="">').appendTo(iebBody);
- //$('<input type="hidden" name="col" value="">').appendTo(iebBody);
- $('<div class="inlineEditBox-cnt"></div>').appendTo(iebBody);
- var iebFoot = $('<div class="modal-footer"></div>').appendTo(frmInlineEdit);
- $('<button class="btn" data-dismiss="modal" aria-hidden="true">Zamknij</button>').appendTo(iebFoot);
- var iebBtnSave = $('<input type="submit" value="Zapisz" class="btn btn-primary btn-save">').appendTo(iebFoot);
- frmInlineEdit.on('submit', function() {
- var data = _inlineEditBox$Node.find('form').serialize();
- _inlineEditBox$Node.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
- function notifyAjaxCallback(data) {
- var notify = {};
- notify.type = (data && data.type)? data.type : '';
- notify.msg = (data && data.msg)? data.msg : '';
- switch (notify.type) {
- case 'success':
- if (!notify.msg) notify.msg = 'Dane poprawnie zaktualizowane';
- break;
- case 'info':
- if (!notify.msg) notify.msg = 'Nie wprowadzono żadnych zmian';
- break;
- case 'error':
- if (!notify.msg) notify.msg = 'Wystąpiły błędy';
- break;
- case 'warning':
- notify.type = 'warn';
- if (!notify.msg) notify.msg = 'Wystąpiły błędy';
- break;
- default:
- notify.msg = 'Nieznany błąd';
- if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
- notify.type = '';
- }
- jQuery.notify(notify.msg, notify.type);
- }
- $.ajax({
- data: data,
- dataType: 'json',
- type: "POST",
- url: priv.options.urlSaveInlineEdit
- })
- .done(function(data, textStatus, jqXHR){
- notifyAjaxCallback(data);
- if (data.record) {
- var year = data.record.SALES_YEAR,
- month = data.record.SALES_MONTH,
- status = data.record.A_STATUS,
- saleValue = parseFloat(data.record.SALES_VALUE),
- marka = data.record.marka,
- state = {}
- ;
- if (month < 10) month = '0' + month;
- // TODO: if marka changed - fix state
- if ('DELETED' === status) {
- state.obroty = {};
- state.obroty[year] = {};
- state.obroty[year][month] = null;
- state.obrotyToMarki = {};
- state.obrotyToMarki[year] = {};
- state.obrotyToMarki[year][month] = null;
- } else {
- state.obroty = {};
- state.obroty[year] = {};
- state.obroty[year][month] = saleValue;
- state.obrotyToMarki = {};
- state.obrotyToMarki[year] = {};
- state.obrotyToMarki[year][month] = marka;
- }
- priv.setState(state);
- }
- _inlineEditBox$Node.modal('hide');
- })
- .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
- if (jqXHR.responseJSON) {
- notifyAjaxCallback(jqXHR.responseJSON);
- }
- else {
- var txt = jqXHR.responseText || 'Wystąpiły błędy';
- if (jqXHR.status == 404) {
- jQuery.notify(jqXHR.responseText, 'error');
- } else {
- jQuery.notify(jqXHR.responseText, 'warn');
- }
- }
- _inlineEditBox$Node.modal('hide');
- });
- return false;
- });
- node.appendTo(_uiNodeCont);//currentNode.replaceWith(node);
- _inlineEditBox$Node = node;
- };
- priv.cellDblClicked = function(e) {
- if ('year' in e.data && 'month' in e.data && e.data.year > 0 && e.data.month > 0) {
- _inlineEditBox$Node.modal();
- _inlineEditBox$Node.show();
- _inlineEditBox$Node.on('shown.bs.modal', function(e) {
- var dialogBox = jQuery(this).find('.modal-dialog'),
- modalBody = dialogBox.find('.modal-body'),
- boudingRect = dialogBox.get(0).getBoundingClientRect();
- dialogBox.css({position: 'absolute', margin:0, top: boudingRect.top, left: boudingRect.left});
- modalBody.css({overflow: 'scroll'});
- dialogBox.resizable({minHeight: 300, minWidth: 300, alsoResize: modalBody});
- dialogBox.draggable();
- });
- _inlineEditBox$Node.on('hidden.bs.modal', function(e) {
- var dialogBox = jQuery(this).find('.modal-dialog'),
- modalBody = dialogBox.find('.modal-body');
- dialogBox.removeAttr('style');
- modalBody.removeAttr('style');
- modalBody.css({padding: '0'});
- dialogBox.resizable();
- dialogBox.draggable();
- dialogBox.resizable('destroy');
- dialogBox.draggable('destroy');
- });
- _inlineEditBox$Node.find('input[name=ID]').val(e.data.id);
- _inlineEditBox$Node.find('input[name=col]').val(e.data.col);
- _inlineEditBox$Node.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
- $.ajax({
- url: priv.options.urlInlineEdit,
- type: 'GET',
- dataType: 'text',
- data: e.data,
- async: true,
- success: function (data) {
- _inlineEditBox$Node.find('.inlineEditBox-cnt').html(data);
- _inlineEditBox$Node.find('.btn-save').show();
- initDateTimePicker(_inlineEditBox$Node);
- _inlineEditBox$Node.find('textarea').autosize();
- var fld = _inlineEditBox$Node.find('input[id^="f"]:first');
- if (fld && !fld.hasClass('se_type-date')) {
- fld.focus();
- fld.keydown(function(event) {
- if (event.which == 13) {
- event.preventDefault();
- _inlineEditBox$Node.find('form').submit();
- }
- });
- }
- },
- error: function (err) {
- if (priv.options.debug) console.log('err');
- }
- });
- } else {
- if (priv.options.debug) console.log('NO data');
- return false;
- }
- };
- priv.onRender = function(e) {// jQuery(_uiNodeCont).trigger('DealsSalesTable:render', [...]);
- if (priv.options.debug) console.log('onRender.arguments:', arguments.length, arguments, 'e:', e);
- if (arguments.length > 1) {
- for (var i=1; i<arguments.length; i++) {
- switch (arguments[i]) {
- case 'body': priv.renderTableBody(); break;
- case 'marki': priv.renderHeaderMarki(); break;
- case 'graphs': priv.renderGraphByYear(); priv.renderGraphByMonth(); break;
- }
- }
- }
- };
- priv.setState = function(state) {
- var oldState = _state,// TODO: use to check what really changed (use extend!)
- renderParts = {};
- if (state.obroty) {
- $.each(state.obroty, function(kYear, vSalesByMonth) {
- $.each(vSalesByMonth, function(kMonth, vSaleValue) {
- if (null === vSaleValue) {
- _state.obroty[kYear][kMonth] = undefined;
- } else {
- _state.obroty[kYear][kMonth] = vSaleValue;
- }
- });
- });
- renderParts['body'] = true;
- renderParts['graphs'] = true;
- }
- /*
- state.obrotyToMarki[year][month] = marka;
- */
- if (state.obrotyToMarki) {
- $.each(state.obrotyToMarki, function(kYear, vMarkiByMonth) {
- $.each(vMarkiByMonth, function(kMonth, vMarka) {
- if (null === vMarka) {
- _state.obrotyToMarki[kYear][kMonth] = undefined;
- } else {
- _state.obrotyToMarki[kYear][kMonth] = vMarka;
- if (undefined === _state.marki[vMarka]) {
- _state.marki[vMarka] = 'default';
- }
- }
- });
- });
- renderParts['marki'] = true;
- }
- renderParts = Object.keys(renderParts);
- if (priv.options.debug) console.log('setState::renderParts: ', renderParts);//TODO:DBG:RMME
- if (renderParts.length > 0) {
- jQuery(_uiNodeCont).trigger('DealsSalesTable:render', renderParts);
- }
- };
- publ.init = function (options) {
- if (priv.options.debug) console.log('DealsSalesTable initialization...');
- //merge supplied options with defaults
- $.extend(priv.options, defaults, options);
- priv.init();
- return publ;
- };
- return publ;
- };
- $.fn.DealsSalesTable = function (options) {
- options = options || {};
- return this.each(function () {
- options.id = this;
- $(this).data('DealsSalesTable', new DealsSalesTable().init(options));
- });
- };
- })(jQuery);
- jQuery(document).ready(function() {
- jQuery('#dealsSalesByMonth').DealsSalesTable({
- url: 'index.php?_route=DealsSales&_task=getDataAjax&telbox=<?php echo $idTelboxes; ?>',
- urlInlineEdit: 'index.php?_route=DealsSales&_task=inlineEditAjax&telbox=<?php echo $idTelboxes; ?>',
- urlSaveInlineEdit: 'index.php?_route=DealsSales&_task=saveInlineAjax&telbox=<?php echo $idTelboxes; ?>',
- initData: <?php echo json_encode($initData); ?>
- });
- });
- </script>
- <script src="stuff/RGraph/libraries/RGraph.common.core.js?_v=20140626"></script>
- <script src="stuff/RGraph/libraries/RGraph.common.dynamic.js?_v=20140626"></script>
- <script src="stuff/RGraph/libraries/RGraph.common.key.js?_v=20140626"></script>
- <script src="stuff/RGraph/libraries/RGraph.drawing.rect.js?_v=20140626"></script>
- <script src="stuff/RGraph/libraries/RGraph.common.tooltips.js?_v=20140626"></script>
- <script src="stuff/RGraph/libraries/RGraph.bar.js?_v=20140626"></script>
- <script src="stuff/RGraph/libraries/RGraph.line.js?_v=20140626"></script>
- <?php endif; ?>
- </div>
- <?php
- }
- }
|