Files
crm.twinpol.com/modules/EcmReceipts2/ListProducts.php

210 lines
6.7 KiB
PHP
Raw Normal View History

2025-05-12 15:44:39 +00:00
<?
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");
?>
<table cellspacing="0" cellpadding="0" border="0"><tr><td><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16"></td><td><h2>Invoices: Saled Products</h2></td></tr></table><br />
<ul class="tablist" style="width:100%;">
<li>
<a class="current" href="#">Basic Search</a>
</li>
</ul>
<form action="index.php" method="get">
<input type="hidden" name="module" value="EcmReceipts" />
<input type="hidden" name="action" value="ListProducts" />
<table style="border-top: 0px none; margin-bottom: 4px;width:100%" class="tabForm" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="dataLabel" width="10%" nowrap="nowrap">
Date from </td>
<td class="dataField" width="30%" nowrap="nowrap">
<input autocomplete="off" name="date_from" id="date_from" value="<? echo $GLOBALS['timedate']->to_display_date($date_from);?>" title="" tabindex="" size="11" maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_from_trigger" align="absmiddle" border="0">
<script type="text/javascript">
Calendar.setup ({
inputField : "date_from",
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
button : "date_from_trigger",
singleClick : true,
dateStr : "",
step : 1
}
);
</script>
</td>
<td class="dataLabel" width="10%" nowrap="nowrap">
Date to </td>
<td class="dataField" width="30%" nowrap="nowrap">
<input autocomplete="off" name="date_to" id="date_to" value="<? echo $GLOBALS['timedate']->to_display_date($date_to);?>" title="" tabindex="" size="11" maxlength="10" type="text">
<img src="themes/default/images/jscalendar.gif" alt="Enter Date" id="date_to_trigger" align="absmiddle" border="0">
<script type="text/javascript">
Calendar.setup ({
inputField : "date_to",
daFormat : "<? echo str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));?>",
button : "date_to_trigger",
singleClick : true,
dateStr : "",
step : 1
}
);
</script>
</td>
<td class="dataLabel" width="10%" nowrap="nowrap">
Category </td>
<td class="dataField" width="30%" nowrap="nowrap">
<select name="category_id">
<option value="">select</option>
<?php
?>
</td>
</tr>
</tbody>
</table>
<input class="button" name="submit" value="Search" type="submit">
<input class="button" name="clear" value="Clear" type="button" onclick="location.href='index.php?module=EcmReceipts&action=ListProducts';"><?
echo '&nbsp;<input type="button" class="button" name="CreateXLS" value="Create XLS" onclick="location.href=\'index.php?module=EcmReceipts&action=CreateXLSProducts&to_pdf=1&date_from='.$date_from.'&date_to='.$date_to.'\';">';
?>
</form><br />
<h2>Date: <? echo $GLOBALS['timedate']->to_display_date($date);?></h2>
<?php
$tds1='<td class="listViewThS1">';
$trs='<tr>';
$tre='</tr>';
$tds='<td class="oddListRowS1">';
$tde='</td>';
$tbs='<table cellpadding="0" cellspacing="0" border="0" class="ListView" style="width:100%;">';
$tbe='</table>';
$t.=$tbs;
$t.=$trs;
$t.=$tds1;
$t.="Lp.";
$t.=$tde;
$t.=$tds1;
$t.="Index";
$t.=$tde;
$t.=$tds1;
$t.="Name";
$t.=$tde;
$t.=$tds1;
$t.="Invoice";
$t.=$tde;
$t.=$tds1;
$t.="Quantity";
$t.=$tde;
$t.=$tds1;
$t.="Price";
$t.=$tde;
$t.=$tds1;
$t.="Total netto";
$t.=$tde;
$t.=$tds1;
$t.="Total Vat";
$t.=$tde;
$t.=$tds1;
$t.="Total brutto";
$t.=$tde;
$t.=$tre;
$i=1;
$z="select ecmreceiptitems.*,ecmreceipts.document_no as dno,ecmreceipts.id as sid,ecmreceipts.type as type,ecminvoiceouts.currency_value as currency_value from ecminvoiceoutitems inner join ecminvoiceouts on ecminvoiceoutitems.ecminvoiceout_id=ecminvoiceouts.id where ecminvoiceouts.deleted='0' and ecminvoiceouts.register_date>='".$date_from."' and ecminvoiceouts.register_date<='".$date_to."' and ecminvoiceoutitems.deleted='0'";
$db = $GLOBALS['db'];
$w=$db->query($z);
echo $db->error;
while($r=$db->fetchByAssoc($w)){
if(!$r['currency_value'])$currency_value=1;
else $currency_value=$r['currency_value'];
$total_netto=$currency_value*$r['price']*$r['quantity'];
$total_vat=$currency_value*$r['price']*$r['quantity']*($r['ecmvat_value']/100);
$total_brutto=$currency_value*$r['price']*$r['quantity']*(1+$r['ecmvat_value']/100);
if($r['type']=="correct"){
$rr=$GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select price,quantity,ecmvat_value from ecmreceiptitems where id='".$r['ecmreceiptitem_id']."'"));
$total_netto-=$currency_value*$rr['price']*$rr['quantity'];
$total_vat-=$currency_value*$rr['price']*$rr['quantity']*($rr['ecmvat_value']/100);
$total_brutto-=$currency_value*$rr['price']*$rr['quantity']*(1+$rr['ecmvat_value']/100);
$r['price']=$currency_value*$rr['price'];
$r['quantity']-=$rr['quantity'];
}
if($r['quantity']==0)continue;
$t.=$trs;
$t.=$tds;
$t.=$i;
$t.=$tde;
$t.=$tds;
$t.=$r['code'];
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?module=EcmProducts&action=DetailView&record='.$r['ecmproduct_id'].'">'.$r['name'].'</a>';
$t.=$tde;
$t.=$tds;
$t.='<a href="index.php?module=EcmReceipts&action=DetailView&record='.$r['sid'].'">'.$r['dno'].'</a>';
$t.=$tde;
$t.=$tds;
$t.=((int)$r['quantity']);
$t.=$tde;
$t.=$tds;
$t.=number_format($r['price'],2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($total_netto,2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($total_vat,2,",",".");
$t.=$tde;
$t.=$tds;
$t.=number_format($total_brutto,2,",",".");
$t.=$tde;
$t.=$tre;
//$sum_price+=$r['price'];
$sum_total_netto+=$total_netto;
$sum_total_vat+=$total_vat;
$sum_total_brutto+=$total_brutto;
$sum_qty+=$r['quantity'];
$i++;
}
$t.=$trs;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=$tde;
$t.=$tds1;
$t.=(int)$sum_qty;
$t.=$tde;
$t.=$tds1;
$t.=@number_format(($sum_total/$sum_qty),2,",",".");
$t.=$tde;
$t.=$tds1;
$t.=number_format($sum_total_netto,2,",",".");
$t.=$tde;
$t.=$tds1;
$t.=number_format($sum_total_vat,2,",",".");
$t.=$tde;
$t.=$tds1;
$t.=number_format($sum_total_brutto,2,",",".");
$t.=$tde;
$t.=$tre;
$t.=$tbe;
echo $t;
?>