D
D
Dmitry Largovich2014-08-26 16:18:53
PHP
Dmitry Largovich, 2014-08-26 16:18:53

1s bitrix php how to create a line in the infoblock with a similar calculation according to a given formula?

Hello.
An infoblock has been created in Bitrix (this is a table that employees fill in, and it calculates/shows the results). There are sections in the infoblock (i.e. rows in the table are created).
In the infoblock, the line "Number of insured persons" - ID 1368 is calculated using a separate formula.
I want some more lines, for example, "Insurance premiums for VHI" - ID 1369, to be calculated in the same way as ID1368. Tell me please how to do it? && - it doesn't help, writes an error (...['SECTION']==1368 && 1369).
d90ec3b961e849e0bda6886aed6870ad.JPG

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();?>
<div class='kpiIndicator'>
  <?//pr($arParams);?>
  <?if($arParams['MAIN_PAGE']!=='Y' && $arParams['EDIT']!=='Y'):?>
    <div class='departmentFilter'>
      <form action='<?=$APPLICATION->GetCurPage();?>' method='get' id='departmentFilterForm'>
        <label>
          Выбор подразделения для вывода отчетности
          <?$APPLICATION->IncludeComponent('areal:department.select','links',
            array(
              'CACHE_TIME'=>'360000',
              'EDIT_KPI'=>'Y',
              'EDIT_EVENTS'=>'N',
            ),
          false);?>
        </label>
      </form>
    </div>
  <?endif;?>
  
  <h2 class='KPIh2'>Основные показатели деятельности компании<?=($arParams['YEAR'] && $arParams['EDIT']==='Y')?' за '.$arParams['YEAR']:'';?></h2>
  <?if($arParams['EDIT']!=='Y'):?>
    <div class='period'>
      <p>Период 
        с <input type="text" class="datepicker" id='dpDateFrom' value='<?=date('Y')?>-01'/> 
        по <input type="text" class="datepicker" id='dpDateTo' value='<?=date('Y')?>-<?=date('m')?>'/>
      </p>
    </div>
  <?else:?>
    <form action='<?=$APPLICATION->GetCurPage();?>' method='get' id='yearFilterForm'>
      <label>
        Выберите год, за который выводить отчет
        <select name='year' id='yearKpiTable'>
          <?for($i=2013;$i<=date('Y');$i++):?>
            <option value='<?=$i?>'<?=($i==$arParams['YEAR'])?' selected':'';?>><?=$i?></option>
          <?endfor;?>
        </select>
      </label>
      <input type='hidden' value='Y' name='edit'/>
    </form>
  <?endif;?>
  
  <?if($arParams['EDIT']!=='Y'):?>
    <table class='kpiIndicatorsTable'>
      <tr>
        <th class="first" width='46%'>ПОКАЗАТЕЛЬ</th>
        <th class="second" width='18%'>ПЛАН (год)</th>
        <th class="third" width='18%'>ФАКТ</th>
        <th class="forth" width='18%'>% ВЫПОЛНЕНИЯ</th>
      </tr>
      <?foreach($arResult['INDICATORS'] as $id=>$arElem):?>
        <?if($arResult['LAST'][$id] && $arElem['SECTION']==1368){
          $arResult['FACT'][$id]=$arResult['LAST'][$id];
        }?>
        <tr>
          <td class='firstCol'><?=$arResult['INDICATOR_NAMES'][$arElem['SECTION']]?></td>
          <td>
            <?$plan=(double)$arElem['PLAN'];?>
            <?=number_format(
              $plan,
              ($plan-(int)$plan)?2:0,
              '.',
              ' '
            )?>
          </td>
          <td>
            <?$fakt=(double)$arResult['FACT'][$id];?>
            <?=number_format(
              $fakt,
              ($fakt-(int)$fakt)?2:0,
              '.',
              ' '
            )?>
          </td>
          <td>
          <?$res=((double)$arElem['PLAN'])?(double)($arResult['FACT'][$id]/$arElem['PLAN']*100):0?>
          <?=number_format(
              $res,
              ($res-(int)$res)?2:0, 
              '.',
              ' '
            );?>
          </td>
        </tr>
      <?endforeach;?>
    </table>
    <?if($arResult['CAN_EDIT']):?>
      <input type='hidden' name='year' id='year' value='<?=date('Y')?>' />
      <input type='hidden' name='link' id='link' value='<?=$APPLICATION->GetCurPageParam('edit=Y',array('edit','save'));?>' />
      <a href='<?=$APPLICATION->GetCurPageParam('edit=Y',array('edit','save'));?>' class='tableEdit'>Редактировать</a>
    <?endif;?>
  <?else:?>
    <?$APPLICATION->SetTitle('');?>
    <form action='<?=$APPLICATION->GetCurPage();?>' id='saveKpiInfo' method='post'>
      <table class='kpiIndicatorsTable edited'>
        <tr>
          <th class="first" rowspan='2'>Показатель</th>
          <th class="second" rowspan='2'>План на год</th>
          <th class="third" colspan='12'>Факт по месяцам</th>
          <th class="forth" rowspan='2' >% выполнения</th>
        </tr>
        <tr>
          <?foreach($arResult['MONTHS'] as $m_id=>$month):?>
            <th class='small'><?=$month?></th>
          <?endforeach;?>
        </tr>
        <?foreach($arResult['INDICATORS'] as $id=>$arElem):?>
          <?if($arResult['LAST'][$id] && $arElem['SECTION']==1368){
            $arResult['FACT'][$id]=$arResult['LAST'][$id];
          }?>
          <tr<?=($arElem['SECTION']==1368)?' class="takeLastValue"':'';?>>
            <td class='firstCol'><?=$arResult['INDICATOR_NAMES'][$arElem['SECTION']]?></td>
            <td class='plan'>
              <input type='text' value='<?=(double)$arElem['PLAN']?>' name='INDICATOR[<?=$id?>][PLAN]' class='planInput'/>
            </td>
            <?foreach($arResult['MONTHS'] as $m_id=>$month):?>
              <td class='small'>
                <input type='text' class='smallInp' value='<?=($arElem['MONTHS'][$m_id+1]['VALUE'])?$arElem['MONTHS'][$m_id+1]['VALUE']:'';?>' name='INDICATOR[<?=$id?>][MONTHS][<?=$m_id+1?>]'/>
                <?if($arElem['MONTHS'][$m_id+1]['ID']):?>
                  <input type='hidden' value='<?=$arElem['MONTHS'][$m_id+1]['ID']?>' name='MONTHS[<?=$id?>][<?=$m_id+1?>]'/>
                <?endif;?>
              </td>
            <?endforeach;?>
            <td class='percent'><?=((double)$arElem['PLAN'])?round((double)($arResult['FACT'][$id]/$arElem['PLAN']*100),2):0;?></td>
          </tr>
        <?endforeach;?>
      </table>
      <?=bitrix_sessid_post()?>
      <div class='tableEdit'>
        <input type='submit' name='save' value='Сохранить' />
        <a class='cancel' href='<?=$APPLICATION->GetCurPageParam('',array('edit','save','year'));?>'>Отменить</a>
      </div>
    </form>
    <?/* <a href='<?=$APPLICATION->GetCurPageParam('save=Y',array('edit','save'));?>'>Сохранить</a> */?>
  <?endif;?> 
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Largovich, 2014-08-27
@tlatypov

Here is the solution! The future very cool specialist in Bitrix helped!
|| $arResult['LAST'][$id] && $arElem['SECTION']==1369 || $arResult['LAST'][$id] && $arElem['SECTION']==1371){
New code with changes

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();?>
<div class='kpiIndicator'>
  <?//pr($arParams);?>
  <?if($arParams['MAIN_PAGE']!=='Y' && $arParams['EDIT']!=='Y'):?>
    <div class='departmentFilter'>
      <form action='<?=$APPLICATION->GetCurPage();?>' method='get' id='departmentFilterForm'>
        <label>
          Выбор подразделения для вывода отчетности
          <?$APPLICATION->IncludeComponent('areal:department.select','links',
            array(
              'CACHE_TIME'=>'360000',
              'EDIT_KPI'=>'Y',
              'EDIT_EVENTS'=>'N',
            ),
          false);?>
        </label>
      </form>
    </div>
  <?endif;?>
  
  <h2 class='KPIh2'>Основные показатели деятельности компании<?=($arParams['YEAR'] && $arParams['EDIT']==='Y')?' за '.$arParams['YEAR']:'';?></h2>
  <?if($arParams['EDIT']!=='Y'):?>
    <div class='period'>
      <p>Период 
        с <input type="text" class="datepicker" id='dpDateFrom' value='<?=date('Y')?>-01'/> 
        по <input type="text" class="datepicker" id='dpDateTo' value='<?=date('Y')?>-<?=date('m')?>'/>
      </p>
    </div>
  <?else:?>
    <form action='<?=$APPLICATION->GetCurPage();?>' method='get' id='yearFilterForm'>
      <label>
        Выберите год, за который выводить отчет
        <select name='year' id='yearKpiTable'>
          <?for($i=2013;$i<=date('Y');$i++):?>
            <option value='<?=$i?>'<?=($i==$arParams['YEAR'])?' selected':'';?>><?=$i?></option>
          <?endfor;?>
        </select>
      </label>
      <input type='hidden' value='Y' name='edit'/>
    </form>
  <?endif;?>
  
  <?if($arParams['EDIT']!=='Y'):?>
    <table class='kpiIndicatorsTable'>
      <tr>
        <th class="first" width='46%'>ПОКАЗАТЕЛЬ</th>
        <th class="second" width='18%'>ПЛАН (год)</th>
        <th class="third" width='18%'>ФАКТ</th>
        <th class="forth" width='18%'>% ВЫПОЛНЕНИЯ</th>
      </tr>
      <?foreach($arResult['INDICATORS'] as $id=>$arElem):?>
        <?if($arResult['LAST'][$id] && $arElem['SECTION']==1368 || $arResult['LAST'][$id] && $arElem['SECTION']==2609 || $arResult['LAST'][$id] && $arElem['SECTION']==2610 || $arResult['LAST'][$id] && $arElem['SECTION']==2611){
          $arResult['FACT'][$id]=$arResult['LAST'][$id];
        }?>
        <tr>
          <td class='firstCol'><?=$arResult['INDICATOR_NAMES'][$arElem['SECTION']]?></td>
          <td>
            <?$plan=(double)$arElem['PLAN'];?>
            <?=number_format(
              $plan,
              ($plan-(int)$plan)?2:0,
              '.',
              ' '
            )?>
          </td>
          <td>
            <?$fakt=(double)$arResult['FACT'][$id];?>
            <?=number_format(
              $fakt,
              ($fakt-(int)$fakt)?2:0,
              '.',
              ' '
            )?>
          </td>
          <td>
          <?$res=((double)$arElem['PLAN'])?(double)($arResult['FACT'][$id]/$arElem['PLAN']*100):0?>
          <?=number_format(
              $res,
              ($res-(int)$res)?2:0, 
              '.',
              ' '
            );?>
          </td>
        </tr>
      <?endforeach;?>
    </table>
    <?if($arResult['CAN_EDIT']):?>
      <input type='hidden' name='year' id='year' value='<?=date('Y')?>' />
      <input type='hidden' name='link' id='link' value='<?=$APPLICATION->GetCurPageParam('edit=Y',array('edit','save'));?>' />
      <a href='<?=$APPLICATION->GetCurPageParam('edit=Y',array('edit','save'));?>' class='tableEdit'>Редактировать</a>
    <?endif;?>
  <?else:?>
    <?$APPLICATION->SetTitle('');?>
    <form action='<?=$APPLICATION->GetCurPage();?>' id='saveKpiInfo' method='post'>
      <table class='kpiIndicatorsTable edited'>
        <tr>
          <th class="first" rowspan='2'>Показатель</th>
          <th class="second" rowspan='2'>План на год</th>
          <th class="third" colspan='12'>Факт по месяцам</th>
          <th class="forth" rowspan='2' >% выполнения</th>
        </tr>
        <tr>
          <?foreach($arResult['MONTHS'] as $m_id=>$month):?>
            <th class='small'><?=$month?></th>
          <?endforeach;?>
        </tr>
        <?foreach($arResult['INDICATORS'] as $id=>$arElem):?>
          <?if($arResult['LAST'][$id] && $arElem['SECTION']==1368 || $arResult['LAST'][$id] && $arElem['SECTION']==2609 || $arResult['LAST'][$id] && $arElem['SECTION']==2610 || $arResult['LAST'][$id] && $arElem['SECTION']==2611){
            $arResult['FACT'][$id]=$arResult['LAST'][$id];
          }?>
          <tr<?=($arElem['SECTION']==1368 || $arElem['SECTION']==2609 || $arElem['SECTION']==2610 || $arElem['SECTION']==2611)?' class="takeLastValue"':'';?>>
            <td class='firstCol'><?=$arResult['INDICATOR_NAMES'][$arElem['SECTION']]?></td>
            <td class='plan'>
              <input type='text' value='<?=(double)$arElem['PLAN']?>' name='INDICATOR[<?=$id?>][PLAN]' class='planInput'/>
            </td>
            <?foreach($arResult['MONTHS'] as $m_id=>$month):?>
              <td class='small'>
                <input type='text' class='smallInp' value='<?=($arElem['MONTHS'][$m_id+1]['VALUE'])?$arElem['MONTHS'][$m_id+1]['VALUE']:'';?>' name='INDICATOR[<?=$id?>][MONTHS][<?=$m_id+1?>]'/>
                <?if($arElem['MONTHS'][$m_id+1]['ID']):?>
                  <input type='hidden' value='<?=$arElem['MONTHS'][$m_id+1]['ID']?>' name='MONTHS[<?=$id?>][<?=$m_id+1?>]'/>
                <?endif;?>
              </td>
            <?endforeach;?>
            <td class='percent'><?=((double)$arElem['PLAN'])?round((double)($arResult['FACT'][$id]/$arElem['PLAN']*100),2):0;?></td>
          </tr>
        <?endforeach;?>
      </table>
      <?=bitrix_sessid_post()?>
      <div class='tableEdit'>
        <input type='submit' name='save' value='Сохранить' />
        <a class='cancel' href='<?=$APPLICATION->GetCurPageParam('',array('edit','save','year'));?>'>Отменить</a>
      </div>
    </form>
    <?/* <a href='<?=$APPLICATION->GetCurPageParam('save=Y',array('edit','save'));?>'>Сохранить</a> */?>
  <?endif;?> 
</div>

M
Maksim Zverev, 2014-08-26
@m1skam

A slightly abstract question, why do lines through sections? O.o

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question