global $db;
if(!$_GET['date_from'])$date_from=date("Y-m-d");
else $date_from=$GLOBALS['timedate']->to_db_date($_GET['date_from']);
$exp=explode("-",$date_from);
$date_from=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600);
if(!$date_from)$date_from=date("Y-m-d");
if(!$_GET['date_to'])$date_to=date("Y-m-d");
else $date_to=$GLOBALS['timedate']->to_db_date($_GET['date_to']);
$exp=explode("-",$date_to);
$date_to=date("Y-m-d",mktime(0,0,0,$exp[1],$exp[2],$exp[0])+24*3600);
if(!$date_to)$date_to=date("Y-m-d");
?>
='".$date_from."'";
if($date_to)$wh[]="register_date<='".$date_to."'";
if($_REQUEST['account_id'])$wh[]="parent_id='".$_REQUEST['account_id']."'";
if($_REQUEST['account_name'])$wh[]="parent_name like '".$_REQUEST['account_name']."%'";
if($_REQUEST['fv_type']) {
if($_REQUEST['fv_type']=='fv')
$wh[]="type = 'normal'";
if($_REQUEST['fv_type']=='fvkor')
$wh[]="type = 'correct'";
}
if(count($wh)>0)$where=" and ".implode(" and ",$wh);
else $where="";
$z="select document_no, id, parent_name, parent_id, type, total_brutto as total, total_netto as subtotal, currency_value from ecminvoiceouts where deleted='0' and canceled='0' ".$where;
$w=$db->query($z);
$result = array();
$sum['subtotal'] = 0;
$sum['total'] = 0;
require_once('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
while ($row = $db->fetchByAssoc($w)) {
if ($row['currency_value'] && floatval($row['currency_value']>0))
$cv = $row['currency_value'];
else
$cv=1;
if (!is_array($result[$row['parent_id']])) {
$result[$row['parent_id']] = array();
$result[$row['parent_id']]['invoices'] = array();
//get account name
$account = $db->fetchByAssoc($db->query("SELECT name FROM accounts WHERE id='".$row['parent_id']."'"));
$result[$row['parent_id']]['parent_name'] = $account['name'];
}
$tmp = array();
$tmp['id'] = $row['id'];
$tmp['document_no'] = $row['document_no'];
$tmp['total'] = $row['total']*$cv;
$tmp['subtotal'] = $row['subtotal']*$cv;
//$tmp['corrects'] = array();
$sum['subtotal'] += $row['subtotal']*$cv;
$sum['total'] += $row['total']*$cv;
//search for corrects
/*
$cor = $db->query("SELECT id, document_no, total, subtotal FROM ecminvoiceouts WHERE ecminvoiceout_id='".$row['id']."' AND canceled='0' AND deleted='0'");
while ($c_row = $db->fetchByAssoc($cor)) {
$tmp2 = array();
$tmp2['id'] = $c_row['id'];
$tmp2['document_no'] = $c_row['document_no'];
$tmp2['total'] = $c_row['total'];
$tmp2['subtotal'] = $c_row['subtotal'];
$tmp['corrects'][] = $tmp2;
$sum['subtotal'] += $c_row['subtotal'];
$sum['total'] += $c_row['total'];
}
*/
$result[$row['parent_id']]['invoices'][] = $tmp;
}
$c1 = ' class="listViewTHS1" ';
$c2 = ' class="oddListRowS1" style="text-align: left; width:120px;"';
$c3 = ' class="oddListRowS1" style="text-align: right;"';
$c4 = ' class="listViewTHS1" style="text-align: right;"';
echo 'Zakres dat :'. $GLOBALS['timedate']->to_display_date($date_from) .' - '.$GLOBALS['timedate']->to_display_date($date_to).'
';
echo '
Wartość sprzedaży
';
echo '| Netto | Brutto |
';
echo '| '.format_number($sum['subtotal']).' | '.format_number($sum['total']).' |
';
foreach ($result as $k =>$v) {
$inv_total = 0;
$inv_subtotal = 0;
echo ''.$v['parent_name'].'
';
echo '| Numer | Netto | Brutto | ';
foreach ($v['invoices'] as $vv) {
echo '
| '.$vv['document_no'].' | '.format_number($vv['subtotal']).' | '.format_number($vv['total']).' |
';
//var_dump($vv['corrects']);
$corrects = false;
$inv_total += $vv['total'];
$inv_subtotal += $vv['subtotal'];
/*
foreach ($vv['corrects'] as $vvv) {
$inv_total += $vvv['total'];
$inv_subtotal += $vvv['subtotal'];
echo '|   '.$vvv['document_no'].' | '.format_number($vvv['subtotal']).' | '.format_number($vvv['total']).' |
';
}
*/
}
echo '| Suma | '.format_number($inv_subtotal).' | '.format_number($inv_total).' |
';
}
//var_dump($result);
?>