<?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.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';
$dtfrom = JFactory::getApplication()->input->getString('dtfrom', '');
$dtto = JFactory::getApplication()->input->getString('dtto', '');
$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);
$db =JFactory::getDBO();
$query = 'select min(odate), max(odate) from #__mfo_docums where (client = '.$db->quote($ulogin).') and (loan = '.$db->quote($loan).')';
$item_minmax = $db->setQuery($query)->loadRow();
$dtmin = JHtml::_('date', $item_minmax[0], 'd.m.Y');
$dtmax = JHtml::_('date', $item_minmax[1], 'd.m.Y');
$documc_js = '
jQuery(function($) {
$.datepicker.regional["ru"] = {
closeText: "Закрыть",
prevText: "<<",
nextText: ">>",
currentText: "Сегодня",
monthNames: ["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"],
monthNamesShort: ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
dayNames: ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"],
dayNamesShort: ["ВС","ПН","ВТ","СР","ЧТ","ПТ","СБ"],
dayNamesMin: ["ВС","ПН","ВТ","СР","ЧТ","ПТ","СБ"],
weekHeader: "Н",
dateFormat: "mm.dd.yy",
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ""
};
$.datepicker.setDefaults($.datepicker.regional["ru"]);
UpdateFilter = function() {
$("#loading").css("display", "block");
$("#adminForm").submit();
};
ClearFilter = function() {
$("#loading").css("display", "block");
$("#dtfrom").val("'.$dtmin.'");
$("#dtto").val("'.$dtmax.'");
$("#adminForm").submit();
};
});
jQuery(document).ready(function($)
{
var outerDiv = $(\'body\');
$(\'<div id="loading"><div class="popup"><div class="loader"><div class="loader-label">'.JText::_('COM_MFO_FTP_UPDATE_POPUP', true).'</div></div></div></div>\').appendTo(outerDiv);
});';
$document->addScriptDeclaration($documc_js);
?>
<div id="mfo" class="clearfix" >
<h1><?php echo JText::sprintf('COM_MFO_H_DOCUMC', $loan); ?></h1>
<hr />
<form action="<?php echo JRoute::_('index.php'); ?>" method="get" name="adminForm" id="adminForm" class="form-horizontal">
<div>
<input type="hidden" name="option" value="com_mfo" />
<input type="hidden" name="view" value="documc" />
<input type="hidden" name="loan" value="<?php echo $loan; ?>" />
<input type="hidden" name="list" value="<?php echo $list; ?>" />
</div>
<div class="control-group">
<div class="controls">
<?php
$query = 'select lupdate from #__mfo_users where client = '.$db->quote($ulogin);
$item_lu = $db->setQuery($query)->loadResult();
echo '<span class="mfo-lupdate">'.JText::sprintf('COM_MFO_FTP_LASTUPDATE', JHtml::_('date', $item_lu, 'd.m.Y H:i')).'</span>';
?>
</div>
</div>
<div class="control-group">
<div class="controls">
<a class="btn btn-info mfo-breturn" href="index.php?view=loans<?php echo $llist; ?>"><?php echo JText::_('COM_MFO_RETURN');?></a>
</div>
</div>
<div class="control-group">
<div class="controls">
<h4><?php echo JText::_('COM_MFO_H_DOCUMS_L'); ?></h4>
<?php
$query = 'select bdate, edate, term, prc, sm, rest, arest, prest, crest, srest from #__mfo_loans where (client = '.$db->quote($ulogin).') and (num = '.$db->quote($loan).')';
$item_loan = $db->setQuery($query)->loadObject();
$rests = $item_loan->arest+$item_loan->prest+$item_loan->srest;
if ($is_contributions) $rests += $item_loan->crest;
echo '<div class="loan-info">';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_BDATE').' <span>'.JHtml::_('date', $item_loan->bdate, 'd.m.Y').'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_EDATE').' <span>'.JHtml::_('date', $item_loan->edate, 'd.m.Y').'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_TERM').' <span>'.$item_loan->term.'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_PRC').' <span>'.number_format($item_loan->prc,4,'.','').'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_SM').' <span>'.number_format($item_loan->sm,2,$dcs,$ths).'</span></div>';
echo '<div class="loan-label">'.JText::_('COM_MFO_TABLE_DOCUMС_LABEL_REST').' <span>'.number_format($item_loan->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>';
?>
</div>
</div>
<div class="control-group">
<div class="controls">
<h4><?php echo JText::_('COM_MFO_H_DOCUMS'); ?></h4>
<script>jQuery(function(){
var form = document.getElementById('adminForm');
jQuery("#dtfrom").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("#dtto").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'); ?>"});
<?php
if ($dtfrom == '')
{echo 'jQuery("#dtfrom").datepicker("setDate","'.$dtmin.'");';} else
{echo 'jQuery("#dtfrom").datepicker("setDate","'.$dtfrom.'");';}
if ($dtto == '')
{echo 'jQuery("#dtto").datepicker("setDate","'.$dtmax.'");';} else
{echo 'jQuery("#dtto").datepicker("setDate","'.$dtto.'");';}
?>
});</script>
<div class="dt-filter">
<span><?php echo JText::_('COM_MFO_FILTER_DT_1'); ?></span><input type="text" class="datepicker" name="dtfrom" id="dtfrom" readonly />
<span><?php echo JText::_('COM_MFO_FILTER_DT_2'); ?></span><input type="text" class="datepicker" name="dtto" id="dtto" readonly />
<a class="btn btn-warning btn-small" href="javascript:UpdateFilter()"><?php echo JText::_('COM_MFO_FILTER_APPLY'); ?></a>
<a class="btn btn-warning btn-small" href="javascript:ClearFilter()"><?php echo JText::_('COM_MFO_FILTER_CLEAR'); ?></a>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<table class="table table-bordered table-striped table-hover">
<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="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_AD'); ?></th>
<th class="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_AC'); ?></th>
<th class="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__D'); ?></th>
<th class="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__C'); ?></th>
<?php if ($is_contributions) : ?>
<th class="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__D'); ?></th>
<th class="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__C'); ?></th>
<?php endif; ?>
<th class="cipher"><?php echo JText::_('COM_MFO_TABLE_DOCUMС__D'); ?></th>
<th class="cipher"><?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++; ?>
<?php $brd = $id_item == 1 ? ' top-brd' : ''; ?>
<tr>
<td class="hc <?php echo $brd; ?>"><?php echo JHtml::_('date', $item->odate, 'd.m.Y'); ?></td>
<td class=" <?php echo $brd; ?>"><?php echo $item->docname; ?></td>
<td class="hr <?php echo $brd; ?>"><?php if ($item->adebet != 0) {$adebet_all += $item->adebet; echo number_format($item->adebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php echo $brd; ?>"><?php if ($item->acredit != 0) {$acredit_all += $item->acredit; echo number_format($item->acredit,2,$dcs,$ths);} ?></td>
<td class="hr <?php echo $brd; ?>"><?php if ($item->pdebet != 0) {$pdebet_all += $item->pdebet; echo number_format($item->pdebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php echo $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 echo $brd; ?>"><?php if ($item->cdebet != 0) {$cdebet_all += $item->cdebet; echo number_format($item->cdebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php echo $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 echo $brd; ?>"><?php if ($item->sdebet != 0) {$sdebet_all += $item->sdebet; echo number_format($item->sdebet,2,$dcs,$ths);} ?></td>
<td class="hr <?php echo $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 hr"><?php echo JText::_('COM_MFO_TABLE_DOCUMС_FOOT_1'); ?></td>
<td class="top-brd hr"><?php echo number_format($adebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hr"><?php echo number_format($acredit_all,2,$dcs,$ths); ?></td>
<td class="top-brd hr"><?php echo number_format($pdebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hr"><?php echo number_format($pcredit_all,2,$dcs,$ths); ?></td>
<?php if ($is_contributions) : ?>
<td class="top-brd hr"><?php echo number_format($cdebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hr"><?php echo number_format($ccredit_all,2,$dcs,$ths); ?></td>
<?php endif; ?>
<td class="top-brd hr"><?php echo number_format($sdebet_all,2,$dcs,$ths); ?></td>
<td class="top-brd hr"><?php echo number_format($scredit_all,2,$dcs,$ths); ?></td>
</tr>
<?php endif; ?>
<tr><td colspan="10" class="top-brd"></td></tr>
</tfoot>
</table>
</div>
</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,6,4).'-'.substr($dtfrom,3,2).'-'.substr($dtfrom,0,2);
$dtmax = substr($dtto,6,4).'-'.substr($dtto,3,2).'-'.substr($dtto,0,2);
$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 between '.$db->quote($dtmin).' and '.$db->quote($dtmax).')');
$query->order('odate, id');
return $query;
}
public function work()
{
return true;
}
}