Files
crm.e5.pl/modules/EcmPurchaseOrders/reportPurchaseOrders.php
2024-04-27 09:23:34 +02:00

279 lines
16 KiB
PHP

<style type="text/css">
.MYoddListRowS1 {
font-size: 10px;
padding-left: 0px;
padding-right: 12px;
padding-bottom: 5px;
padding-top: 3px;
vertical-align: middle;
}
.MYlistViewThS1{
font-size: 10px;
font-weight: bold;
text-align: left;
padding-left: 0px;
padding-right: 11px;
padding-bottom: 5px;
padding-top: 3px;
border-left: none;
border-right: none;
border-top: 1px solid #cccccc;
border-bottom: 1px solid #cccccc;
background:#ebebed;
}
</style>
<script type="text/javascript">
function createOrderLink(column) {
<?php
if ($_GET['order_by'])
echo 'var order_by =\''.$_GET['order_by'].'\';';
else
echo 'var order_by =\'p.name\';';
if ($_GET['order_type'])
echo 'var order_type =\''.$_GET['order_type'].'\';';
else
echo 'var order_type =\'ASC\';';
//$_GET copy
$get='';
echo 'var get=\'\';';
foreach ($_GET as $k => $v) {
if (($k!='order_by') && ($k!='order_type'))
if (is_array($v)) {
$tmp = '';
foreach ($v as $k2=>$v2)
$tmp.='&'.$k.'[]='.$v2;
echo 'var get=get+\''.$tmp.'\';';
} else
echo 'var get=get+\'&'.$k.'='.$v.'\';';
}
?>
var link;
if (column == order_by) {
if (order_type == 'ASC')
link='index.php?order_by='+column+'&order_type=DESC'+get;
if (order_type == 'DESC') {
link='index.php?order_by='+column+'&order_type=ASC'+get;
}
} else
link='index.php?order_by='+column+'&order_type=ASC'+get;
location.href = link;
}
function showhide(id) {
var el = document.getElementById(id);
if (el.style.display == "none")
el.style.display="block";
else
el.style.display="none";
}
function setTableSize() {
var header_height=document.getElementById('header').offsetHeight;
var header_width=document.getElementById('header').offsetWidth;
//var left_width=document.getElementById('left').offsetWidth;
var left_width = 0;
var screen_height = screen.height;
var screen_width = screen.width;
var new_height = (screen_height-header_height-300)+'px';
document.getElementById('myListView').style.height=new_height;
var new_width = (screen_width-left_width-50);
document.getElementById('tableDiv').style.width=new_width+'px';
}
function clearSearch() {
link='index.php?module=EcmPurchaseOrders&action=reportPurchaseOrders';
location.href = link;
}
</script>
<?php global $mod_strings;?>
<table cellspacing="0" cellpadding="0" border="0"><tr><td width="19"><img src="themes/Sugar/images/EcmProducts.gif" style="margin-top: 3px; margin-right: 3px;" alt="EcmProducts" width="16" border="0" height="16"></td>
<td width="402"><h2><?php echo $mod_strings['LBL_REPORT']; ?></h2></td></tr></table><br />
<div id="search_box">
<ul class="tablist">
<li>
<a class="current" href="#"><?php echo $mod_strings['LBL_REPORT_SEARCH']; ?></a>
</li>
</ul>
<form action="index.php" method="get" name="search_reports">
<input type="hidden" name="module" value="EcmPurchaseOrders" />
<input type="hidden" name="action" value="reportPurchaseOrders" />
<table style="border-top: 0px none; margin-bottom: 4px;" class="tabForm" width="100%" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_PRODUCT_NAME']; ?> </td>
<td class="dataField" width="18%" nowrap="nowrap">
<input name="product_name" id="product_name" size="30" maxlength="255" value="<? echo $_GET['product_name'];?>" title="" tabindex="" type="text">
</td>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_PRODUCT_CODE']; ?> </td>
<td class="dataField" width="18%" nowrap="nowrap">
<input name="product_code" id="product_code" size="30" maxlength="255" value="<? echo $_GET['product_code'];?>" title="" tabindex="" type="text">
</td>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_ORDER_NO']; ?> </td>
<td class="dataField" width="18%" nowrap="nowrap">
<input name="purchase_order_number" id="purchase_order_number" size="30" maxlength="255" value="<? echo $_GET['purchase_order_number'];?>" title="" tabindex="" type="text">
</td>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_ORDER_STATUS']; ?></td>
<td class="dataField" width="26%" nowrap="nowrap">
<select name="purchase_order_status[]" multiple="true" size="6" style="width: 150px;">
<option value=""></option>
<?
foreach ($GLOBALS['app_list_strings']['ecmpurchaseorders_status_dom'] as $k=>$v) {
echo '<option value="'.$k.'"';
if (count($_GET['purchase_order_status']) > 0)
foreach ($_GET['purchase_order_status'] as $status) {
if($k==$status)echo ' selected';
}
echo '>'.$v.'</option>';
}
?>
</td>
</tr><tr>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_USER']; ?> </td>
<td class="dataField" width="18%" nowrap="nowrap">
<select name="user"><option value=""></option>
<?
$w=$GLOBALS['db']->query("select id, first_name, last_name from users where deleted=0 and status='Active' order by last_name asc");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
echo '<option value="'.$r['id'].'"';
if($r['id']==$_REQUEST['user'])echo ' selected';
echo '>'.$r['first_name'].' '.$r['last_name'].'</option>';
}
?>
</td>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_PRODUCT_CATEGORY']; ?> </td>
<td class="dataField" width="18%" nowrap="nowrap">
<select name="category"><option value=""></option>
<?
$w=$GLOBALS['db']->query("select id,name from ecmproductcategories where deleted='0' order by name asc");
while($r=$GLOBALS['db']->fetchByAssoc($w)){
echo '<option value="'.$r['id'].'"';
if($r['id']==$_REQUEST['category'])echo ' selected';
echo '>'.$r['name'].'</option>';
}
?>
</td>
<td class="dataLabel" width="5%" nowrap="nowrap">
<?php echo $mod_strings['LBL_REPORT_TRACKING_NO']; ?> </td>
<td class="dataField" width="18%" nowrap="nowrap">
<input name="tracking_no" id="tracking_no" size="30" maxlength="255" value="<? echo $_GET['product_name'];?>" title="" tabindex="" type="text">
</td>
<td class="dataLabel" width="20%" nowrap="nowrap"><?php echo $mod_strings['LBL_REPORT_ACCOUNT_NAME']; ?></td>
<td class="dataField" width="30%" nowrap="nowrap">
<input name="account_name" readonly="readonly" tabindex="" id="account_name" size="" value="<?php echo $_REQUEST['account_name'];?>" title="" type="text">
<input name="account_id" id="account_id" value="<?php echo $_REQUEST['account_id'];?>" type="hidden">
<input name="btn_account_name" tabindex="" title="Select [Alt+T]" accesskey="T" class="button" value="Select" onclick='open_popup("Accounts", 600, 400, "", true, false, {"call_back_function":"set_return","form_name":"search_reports","field_to_name_array":{"id":"account_id","name":"account_name"}}, "single", true);' type="button">
</td>
</tr>
</tbody>
</table>
</div>
<input class="button" name="submit" value="<?php echo $mod_strings['LBL_REPORT_BTN_SEARCH']; ?>" type="submit">
<input class="button" name="hide" value="<?php echo $mod_strings['LBL_REPORT_BTN_CLEAR']; ?>" type="button" onClick="clearSearch();">
<input class="button" name="hide" value="<?php echo $mod_strings['LBL_REPORT_BTN_HIDESHOW']; ?>" type="button" onClick="showhide('search_box');">
<?php
//create GET for XLS
$get='';
foreach ($_GET as $k=>$v) {
if (($k!='module') && ($k!='action') && ($k!='purchase_order_status') && ($k!='submit') && ($k!='usertheme'))
$get.='&'.$k.'='.$v;
}
if (count($_GET['purchase_order_status']) > 0) {
$wh_status = array();
foreach ($_GET['purchase_order_status'] as $status) {
$get.='&purchase_order_status[]='.$status;
}
}
?>
<input class="button" name="hide" value="<?php echo $mod_strings['LBL_CREATE_XLS']; ?>" type="button" onClick="window.location='index.php?module=EcmPurchaseOrders&action=createReportXLS<? echo $get; ?>'">
<?php
//create query
//$wh_products = array();
//$wh_orders = array();
if ($_GET['submit']) {
if ($_GET['product_name']) $wh_products[] = "p.name LIKE '%".$_GET['product_name']."%'";
if ($_GET['product_code']) $wh_products[] = "p.code LIKE '%".$_GET['product_code']."%'";
if ($_GET['purchase_order_number']) $wh_orders[] = "o.document_no LIKE '%".$_GET['purchase_order_number']."%'";
if (count($_GET['purchase_order_status']) > 0) {
$wh_status = array();
foreach ($_GET['purchase_order_status'] as $status) {
$wh_status[] = "o.status ='".$status."'";
}
$wh_orders[] = "(".implode(" OR ", $wh_status).")";
}
if ($_GET['user']) $wh_orders[] = "o.assigned_user_id = '".$_GET['user']."'";
if ($_GET['category']) $wh_products[] = "p.product_category_id = '".$_GET['category']."'";
if ($_GET['tracking_no']) $wh_orders[] = "o.tracking_no LIKE '%".$_GET['tracking_no']."%'";
if ($_GET['account_id']) $wh_orders[] = "o.parent_id = '".$_GET['account_id']."'";
}
if (($_GET['order_by']) && $_GET['order_type'])
$order_by=" ORDER BY ".$_GET['order_by'].' '.$_GET['order_type'];
else $order_by=" ORDER BY o.date_entered DESC";
$query = "SELECT p.name, p.product_category_name, o.date_entered, o.document_no, o.status, po.quantity, po.price_start, o.delivery_date, o.tracking_no, u.first_name, u.last_name, po.ecmpurchaseorder_id, po.ecmproduct_id, p.code, o.parent_id, o.parent_name FROM ecmpurchaseorderitems AS po ";
$query.="INNER JOIN ecmproducts AS p ON p.id=po.ecmproduct_id ";
if (isset($wh_products)) $query.=" AND ".implode(" AND ", $wh_products);
$query.="INNER JOIN ecmpurchaseorders AS o ON o.id=po.ecmpurchaseorder_id AND o.deleted='0' ";
if (isset($wh_orders)) $query.=" AND ".implode(" AND ", $wh_orders);
$query.="INNER JOIN users As u ON o.assigned_user_id=u.id";
$query = $query.$order_by;
echo $query;
?>
<div id="tableDiv" style="overflow-x: scroll; width: 100px">
<table width="100%"><tr><td>
<div style="overflow-y: scroll;">
<table width="1490" id="myListViewTableHead" class="h3Row" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 200px; min-width: 200px; max-width:200px; " class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('p.code')"><?php echo $mod_strings['LBL_REPORT_LIST_CODE']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 410px; min-width: 410px; max-width:410px; "class="MYlistViewThS1" ><a class="listViewThLinkS1" href="javascript:createOrderLink('p.name')"><?php echo $mod_strings['LBL_REPORT_LIST_NAME']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 180px; min-width: 180px; max-width:180px; " class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('p.product_category_name')"><?php echo $mod_strings['LBL_REPORT_LIST_CATEGORY']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 130px; min-width: 130px; max-width:130px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('o.parent_name')"><?php echo $mod_strings['LBL_REPORT_ACCOUNT_NAME']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 60px; min-width: 60px; max-width:60px; "class="MYlistViewThS1" ><a class="listViewThLinkS1" href="javascript:createOrderLink('po.quantity')"><?php echo $mod_strings['LBL_REPORT_LIST_QUANTITY']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 60px; min-width: 60px; max-width:60px; "class="MYlistViewThS1" ><a class="listViewThLinkS1" href="javascript:createOrderLink('po.price_start')">Cena<img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 80px; min-width: 80px; max-width:80px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('o.date_entered')"><?php echo $mod_strings['LBL_REPORT_LIST_ORDER_DATE']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 90px; min-width: 90px; max-width:90px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('o.delivery_date')"><?php echo $mod_strings['LBL_REPORT_LIST_DELIVERY_DATE']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 80px; min-width: 80px; max-width:80px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('o.document_no')"><?php echo $mod_strings['LBL_REPORT_ORDER_NO']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 80px; min-width: 80px; max-width:80px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('o.status')"><?php echo $mod_strings['LBL_REPORT_ORDER_STATUS']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 130px; min-width: 130px; max-width:130px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('p.user')"><?php echo $mod_strings['LBL_REPORT_USER']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
<td style="width: 130px; min-width: 130px; max-width:130px; "class="MYlistViewThS1"><a class="listViewThLinkS1" href="javascript:createOrderLink('o.tracking_no')"><?php echo $mod_strings['LBL_REPORT_TRACKING_NO']; ?><img src="themes/Sugar/images/arrow.gif" border="0"/></td>
</tr>
</table>
</div>
<div id="myListView" style="overflow-y: scroll;">
<table id = "myListViewTableData" border="0" cellpadding="0" cellspacing="0">
<?php
//$max_width = "style=\"max-width: 200px;\"";
$result = $GLOBALS['db']->query($query);
while ($r=$GLOBALS['db']->fetchByAssoc($result)) {
foreach ($r as $k => $v) if (!$v) $v="&nbsp";
// style=\"width: 100px; min-width: 100px; max-width:100px; \"
echo "<tr><td style=\"width: 200px; min-width: 200px; max-width:200px; \" class=\"MYoddListRowS1\"><a href=\"index.php?module=EcmProducts&action=DetailView&record=".$r['ecmproduct_id']."\">".$r['code']."</a></td>";
echo "<td style=\"width: 410px; min-width: 410px; max-width:410px; \" class=\"MYoddListRowS1\"><a href=\"index.php?module=EcmProducts&action=DetailView&record=".$r['ecmproduct_id']."\">".$r['name']."</a></td>";
echo "<td style=\"width: 170px; min-width: 170px; max-width:170px; \" class=\"MYoddListRowS1\">".$r['product_category_name']."</td>";
echo "<td style=\"width: 130px; min-width: 130px; max-width:130px; \"class=\"MYoddListRowS1\"><a href=\"index.php?module=Accounts&action=DetailView&record=".$r['parent_id']."\">".$r['parent_name']."</a></td>";
echo "<td style=\"width: 50px; min-width: 50px; max-width:50px; \" class=\"MYoddListRowS1\">".$r['quantity']."</td>";
echo "<td style=\"width: 60px; min-width: 60px; max-width:60px; \" class=\"MYoddListRowS1\">".$r['price_start']."</td>";
echo "<td style=\"width: 80px; min-width: 80px; max-width: 80px; \" class=\"MYoddListRowS1\">".substr($r['date_entered'],0,10)."</td>";
echo "<td style=\"width: 80px; min-width: 80px; max-width:80px; \" class=\"MYoddListRowS1\">".substr($r['delivery_date'],0,10)."</td>";
echo "<td style=\"width: 80px; min-width: 80px; max-width:80px; \" class=\"MYoddListRowS1\"><a href=\"index.php?module=EcmPurchaseOrders&action=DetailView&record=".$r['ecmpurchaseorder_id']."\">".$r['document_no']."</a></td>";
echo "<td style=\"width: 80px; min-width: 80px; max-width:80px; \" class=\"MYoddListRowS1\">".$GLOBALS['app_list_strings']['ecmpurchaseorders_status_dom'][$r['status']]."</td>";
echo "<td style=\"width: 130px; min-width: 130px; max-width:130px; \" class=\"MYoddListRowS1\">".$r['first_name'].' '.$r['last_name']."</td>";
echo "<td style=\"width: 130px; min-width: 130px; max-width:130px; \" class=\"MYoddListRowS1\">".$r['tracking_no']."</td></tr>";
}
?>
</table>
</div>
</td></tr></table>
</div>
<script type="text/javascript">setTableSize();</script>