<?php
defined('_JEXEC') or die;
JHtml::_('bootstrap.tooltip');
JHtml::_('jquery.framework');
$document = JFactory::getDocument();
$document->addStyleSheet('/media/com_mfo/css/jquery-ui-1.10.4.custom.min.css');
$document->addStyleSheet('/media/com_mfo/css/com_mfo_front.css');
$document->addScript('/media/com_mfo/js/jquery-ui-1.10.4.custom.js');
$loan = JFactory::getApplication()->input->getString('loan', '');
$list = JFactory::getApplication()->input->getString('list', '0');
$llist = '';
if ($list == '1') $llist = 'c';
if ($list == '2') $llist = 'd';
$ulogin = JFactory::getUser()->username;
$params = JComponentHelper::getParams('com_mfo');
$dcs = $params->get('mfo_decimal_separator', '.');
$ths = $params->get('mfo_thousands_separator', ' ');
if ($ths == '=') $ths = '';
$is_contributions = $params->get('mfo_is_contributions_columns', 0);
?>
<script type="text/javascript">
UpdateFilter = function()
{
var form = document.getElementById('adminForm');
jQuery('#loading').css('display', 'block');
form.dtfrom.value = form.datepicker1.value;
form.dtto.value = form.datepicker2.value;
form.submit();
};
jQuery(document).ready(function($)
{
var outerDiv = $('body');
$('<div id="loading"><div class="popup"><div class="loader"><div class="loader-label"><?php echo JText::_('COM_MFO_FTP_UPDATE_POPUP', true); ?></div></div></div></div>').appendTo(outerDiv);
});
</script>
<div id="mfo" class="clearfix" >
<h1><?php echo JText::sprintf('COM_MFO_H_DOCUMC', $loan); ?></h1>
<form action="<?php echo JRoute::_('index.php?option=com_mfo&view=documc&loan='.$loan.'&list='.$list); ?>" name="adminForm" id="adminForm" class="form-horizontal">
<div class="control-group mfo-item">
<div class="controls">
<?php
$db =JFactory::getDBO();
$query = 'select lupdate from #__mfo_users where client = '.$db->quote($ulogin);
$item = $db->setQuery($query)->loadResult();
echo '<span class="mfo-lupdate">'.JText::sprintf('COM_MFO_FTP_LASTUPDATE', JHtml::_('date', $item, 'd.m.Y H:i')).'</span>';
?>
</div>
<div class="controls">
<a class="btn a pull-right" href="/index.php?option=com_mfo&view=loans<?php echo $llist; ?>"><?php echo JText::_('COM_MFO_RETURN');?></a>
</div>
</div>
<div class="control-group">
<div class="controls">
<h6><?php echo JText::_('COM_MFO_H_DOCUMS_L'); ?></h6>
<?php
$query = 'select bdate, edate, term, termtp, prc, sm, rest, arest, prest, crest, srest from #__mfo_loans where (client = '.$db->quote($ulogin).') and (num = '.$db->quote($loan).')';
$item = $db->setQuery($query)->loadObject();
$rests = $item->arest+$item->prest+$item->srest;
if ($is_contributions) $rests += $item->crest;
switch ((int)$item->termtp)
{
case 1:
$termtp = JText::_('COM_MFO_TERM_DAY');
break;
case 7:
$termtp = JText::_('COM_MFO_TERM_WEEK');
break;
case 30:
$termtp = JText::_('COM_MFO_TERM_MONTH');
break;
default:
$termtp = JText::_('COM_MFO_TERM_MONTH');
break;
}
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_BDATE').' <span>'.JHtml::_('date', $item->bdate, 'd.m.Y').'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_EDATE').' <span>'.JHtml::_('date', $item->edate, 'd.m.Y').'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_TERM').' <span>'.$item->term.$termtp.'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_PRC').' <span>'.number_format($item->prc,4,'.','').'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_SM').' <span>'.number_format($item->sm,2,$dcs,$ths).'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_REST').' <span>'.number_format($item->rest,2,$dcs,$ths).'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_RESTS').' <span>'.number_format($rests,2,$dcs,$ths).'</span></div>';
echo '<div class="loan-label last"></div>';
?>
</div>
</div>
<h6><?php echo JText::_('COM_MFO_H_DOCUMS_D'); ?></h6>
<div class="control-group">
<div class="controls">
<?php
$query = 'select min(odate), max(odate) from #__mfo_docums where (client = '.$db->quote($ulogin).') and (loan = '.$db->quote($loan).')';
$item = $db->setQuery($query)->loadRow();
$dtmin = $item[0];
$dtmax = $item[1];
?>
<script>jQuery(function(){
jQuery("#datepicker1").datepicker({dateFormat:"dd.mm.yy",changeMonth:true,changeYear:true,showButtonPanel:true,minDate:"<?php echo JHtml::_('date', $dtmin, 'd.m.Y'); ?>",maxDate:"<?php echo JHtml::_('date', $dtmax, 'd.m.Y'); ?>"});
jQuery("#datepicker1").datepicker(jQuery.datepicker.regional["ru"]);
jQuery("#datepicker1").datepicker("setDate","<?php echo JHtml::_('date', $dtmin, 'd.m.Y'); ?>");
jQuery("#datepicker2").datepicker({dateFormat:"dd.mm.yy",changeMonth:true,changeYear:true,showButtonPanel:true,minDate:"<?php echo JHtml::_('date', $dtmin, 'd.m.Y'); ?>",maxDate:"<?php echo JHtml::_('date', $dtmax, 'd.m.Y'); ?>"});
jQuery("#datepicker2").datepicker(jQuery.datepicker.regional["ru"]);
jQuery("#datepicker2").datepicker("setDate","<?php echo JHtml::_('date', $dtmax, 'd.m.Y'); ?>");
});</script>
<div class="dt-filter">
<span><?php echo JText::_('COM_MFO_FILTER_DT_1'); ?></span><input type="text" class="datepicker" name="datepicker1" id="datepicker1" readonly>
<span><?php echo JText::_('COM_MFO_FILTER_DT_2'); ?></span><input type="text" class="datepicker" name="datepicker2" id="datepicker2" readonly>
<span><a href="javascript:UpdateFilter()"> Применить фильтр </a></span>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<table class="mfo-table mfo-small">
<thead>
<tr>
<th rowspan="2"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_ODATE'); ?></th>
<th rowspan="2"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_DOCNAME'); ?></th>
<th colspan="2"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_A'); ?></th>
<th colspan="2"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_P'); ?></th>
<?php if ($is_contributions) : ?>
<th colspan="2"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_C'); ?></th>
<?php endif; ?>
<th colspan="2"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_S'); ?></th>
</tr>
<tr>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_AD'); ?></th>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_AC'); ?></th>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__D'); ?></th>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__C'); ?></th>
<?php if ($is_contributions) : ?>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__D'); ?></th>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__C'); ?></th>
<?php endif; ?>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__D'); ?></th>
<th class="w80"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__C'); ?></th>
</tr>
</thead>
<tbody>
<?php $id_item = 0;
if (count($this->items)) :
$adebet_all = 0;
$acredit_all = 0;
$pdebet_all = 0;
$pcredit_all = 0;
$cdebet_all = 0;
$ccredit_all = 0;
$sdebet_all = 0;
$scredit_all = 0;
foreach ($this->items as $i => $item) :
$id_item++; ?>
<tr>
<td class="hc <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php echo JHtml::_('date', $item->odate, 'd.m.Y'); ?></td>
<td class=" <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php echo $item->docname; ?></td>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->adebet != 0) {$adebet_all += $item->adebet; echo number_format($item->adebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->acredit != 0) {$acredit_all += $item->acredit; echo number_format($item->acredit,2,$dcs,$ths);} ?></td>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->pdebet != 0) {$pdebet_all += $item->pdebet; echo number_format($item->pdebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->pcredit != 0) {$pcredit_all += $item->pcredit; echo number_format($item->pcredit,2,$dcs,$ths);} ?></td>
<?php if ($is_contributions) : ?>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->cdebet != 0) {$cdebet_all += $item->cdebet; echo number_format($item->cdebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->ccredit != 0) {$ccredit_all += $item->ccredit; echo number_format($item->ccredit,2,$dcs,$ths);} ?></td>
<?php endif; ?>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->sdebet != 0) {$sdebet_all += $item->sdebet; echo number_format($item->sdebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php if ($id_item == 1) {echo 'top-brd';}?>"><?php if ($item->scredit != 0) {$scredit_all += $item->scredit; echo number_format($item->scredit,2,$dcs,$ths);} ?></td>
</tr>
<?php
endforeach; ?>
<?php else : ?>
<tr><td colspan="10" class="top-brd"><?php echo JText::_('COM_MFO_TABLE_NO_DATA'); ?></td></tr>
<?php endif; ?>
</tbody>
<tfoot>
<?php if (count($this->items)) : ?>
<tr>
<td colspan="2" class="top-brd hrb"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_FOOT_1'); ?></td>
<td class="top-brd hrb"><?php echo number_format($adebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hrb"><?php echo number_format($acredit_all,2,$dcs,$ths); ?></td>
<td class="top-brd hrb"><?php echo number_format($pdebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hrb"><?php echo number_format($pcredit_all,2,$dcs,$ths); ?></td>
<?php if ($is_contributions) : ?>
<td class="top-brd hrb"><?php echo number_format($cdebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hrb"><?php echo number_format($ccredit_all,2,$dcs,$ths); ?></td>
<?php endif; ?>
<td class="top-brd hrb"><?php echo number_format($sdebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hrb"><?php echo number_format($scredit_all,2,$dcs,$ths); ?></td>
</tr>
<tr>
<td colspan="2" class="top-brd hrb"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_FOOT_2'); ?></td>
<td colspan="2" class="top-brd hrb"><?php echo number_format($adebet_all-$acredit_all,2,$dcs,$ths); ?></td>
<td colspan="2" class="top-brd hrb"><?php echo number_format($pdebet_all-$pcredit_all,2,$dcs,$ths); ?></td>
<?php if ($is_contributions) : ?>
<td colspan="2" class="top-brd hrb"><?php echo number_format($cdebet_all-$ccredit_all,2,$dcs,$ths); ?></td>
<?php endif; ?>
<td colspan="2" class="top-brd hrb"><?php echo number_format($sdebet_all-$scredit_all,2,$dcs,$ths); ?></td>
</tr>
<?php endif; ?>
<tr><td colspan="10" class="top-brd"></td></tr>
</tfoot>
</table>
</div>
</div>
<div>
<input type="hidden" name="type" value="" />
<input type="hidden" name="dtfrom" value="" />
<input type="hidden" name="dtto" value="" />
<input type="hidden" name="task" value="documc.work" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
</div>
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class MfoModelDocumc extends JModelList
{
public function getForm($data = array(), $loadData = true)
{
$form = $this->loadForm($this->option.'.documc', 'documc', array('control'=>'jform', 'load_data'=>$loadData));
if (empty($form)) {return false;}
return $form;
}
protected function getListQuery()
{
$ulogin = JFactory::getUser()->username;
$loan = JFactory::getApplication()->input->getString('loan', '');
$dtfrom = JFactory::getApplication()->input->getString('dtfrom');
$dtto = JFactory::getApplication()->input->getString('dtto');
$dtmin = substr($dtfrom,8,2).'-'.substr($dtfrom,5,2).'-'.substr($dtfrom,0,4);
$dtmax = substr($dtto,8,2).'-'.substr($dtto,5,2).'-'.substr($dtto,0,4);
print_r('1:'.$dtfrom.'<br />2:'.$dtto.'<br />'); // Даты отсутствуют
$db = JFactory::getDBO();
if (!$dtmin or !$dtmax) {
$query = 'select min(odate), max(odate) from #__mfo_docums where (client = '.$db->quote($ulogin).') and (loan = '.$db->quote($loan).')';
$item = $db->setQuery($query)->loadRow();
$dtmin = $item[0];
$dtmax = $item[1];
}
$query = $db->getQuery(true);
$query->select('odate, docname, adebet, acredit, pdebet, pcredit, cdebet, ccredit, sdebet, scredit');
$query->from('#__mfo_docums');
$query->where('client = '.$db->quote($ulogin));
$query->where('loan = '.$db->quote($loan));
$query->where('odate >= '.$db->quote($dtmin));
$query->where('odate <= '.$db->quote($dtmax));
$query->order('odate, id');
return $query;
}
public function work()
{
$dtmin = $_GET["dtfrom"];
$dtmax = $_GET["dtto"];
print_r('1:'.$dtmin.'<br />2:'.$dtmax.'<br />'); // Выводит даты
return true;
}
}