150 lines
4.2 KiB
PHP
150 lines
4.2 KiB
PHP
|
|
<?php
|
|||
|
|
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
|||
|
|
die ( 'Not A Valid Entry Point' );
|
|||
|
|
/**
|
|||
|
|
* ********************* PREPARE ********************
|
|||
|
|
*/
|
|||
|
|
global $app_list_strings;
|
|||
|
|
setlocale(LC_MENETARY,"pl-PL");
|
|||
|
|
$db = $GLOBALS ['db'];
|
|||
|
|
$data = array ();
|
|||
|
|
$date_from = NULL;
|
|||
|
|
$date_to = NULL;
|
|||
|
|
$user_id = NULL;
|
|||
|
|
$doc_name = NULL;
|
|||
|
|
$category_id = NULL;
|
|||
|
|
$status = "";
|
|||
|
|
$query = "";
|
|||
|
|
$where = "";
|
|||
|
|
$suma =0;
|
|||
|
|
$whereraport = "";
|
|||
|
|
// Pobieranie danych z formularza
|
|||
|
|
if(!$_GET['first_load']){
|
|||
|
|
$first_load = 0;
|
|||
|
|
}else{
|
|||
|
|
$first_load = $_GET['first_load'];
|
|||
|
|
}
|
|||
|
|
if(!$_GET['date_from']){
|
|||
|
|
$date_from = NULL;
|
|||
|
|
}else{
|
|||
|
|
$date_from = $_GET['date_from'];
|
|||
|
|
$where = $where. " d.date_entered >= STR_TO_DATE('".$date_from."','%d.%m.%Y') AND ";
|
|||
|
|
}
|
|||
|
|
if(!$_GET['date_to']){
|
|||
|
|
$date_to = NULL;
|
|||
|
|
}else{
|
|||
|
|
$date_to = $_GET['date_to'];
|
|||
|
|
$where = $where. " d.date_entered <= STR_TO_DATE('".$date_to."','%d.%m.%Y') AND ";
|
|||
|
|
}
|
|||
|
|
if(!$_GET['doc_name']){
|
|||
|
|
$doc_name = NULL;
|
|||
|
|
}else{
|
|||
|
|
$doc_name = $_GET['doc_name'];
|
|||
|
|
$where = $where. " d.document_name LIKE '%".$doc_name."%'AND ";
|
|||
|
|
}
|
|||
|
|
if(!$_GET['category_id']){
|
|||
|
|
$category_id = NULL;
|
|||
|
|
}else{
|
|||
|
|
$category_id = $_GET['category_id'];
|
|||
|
|
$where = $where. " d.category_id = '" . $category_id . "' AND ";
|
|||
|
|
}
|
|||
|
|
if($_GET['status']== NULL){
|
|||
|
|
$status = NULL;
|
|||
|
|
}else{
|
|||
|
|
$status = $_GET['status'];
|
|||
|
|
$whereraport = " du.document_id = d.id AND du.accepted = ". $status. " AND ";
|
|||
|
|
$fromraport = " documents_user du, ";
|
|||
|
|
}
|
|||
|
|
//formatowanie daty
|
|||
|
|
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
|
|||
|
|
$currentDate = $GLOBALS['timedate']->to_display_date($date_from);
|
|||
|
|
$date_from = $GLOBALS['timedate']->to_display_date($date_from);
|
|||
|
|
$date_to = $GLOBALS['timedate']->to_display_date($date_to);
|
|||
|
|
|
|||
|
|
//Tworzenie zapytania zapytnaie do bazy
|
|||
|
|
$query = "SELECT
|
|||
|
|
DATE_FORMAT(DATE(d.document_date), '%d-%m-%Y') as docdate,
|
|||
|
|
d.document_name as docname,
|
|||
|
|
d.id as docid,
|
|||
|
|
DATE_FORMAT(DATE(d.date_entered), '%d-%m-%Y') as docdateentered,
|
|||
|
|
d.category_id as doccategory,
|
|||
|
|
d.description as docdes,
|
|||
|
|
ifnull(d.value,0) as docwartosc,
|
|||
|
|
u.first_name as username,
|
|||
|
|
u.last_name as userlastname
|
|||
|
|
FROM
|
|||
|
|
".
|
|||
|
|
$fromraport . "
|
|||
|
|
documents d
|
|||
|
|
left join users u on u.id = d.created_by
|
|||
|
|
left join accounts a on d.parent_id = a.id
|
|||
|
|
WHERE
|
|||
|
|
" . $where . $whereraport . " d.deleted = 0";
|
|||
|
|
echo $query;
|
|||
|
|
if($first_load==0){
|
|||
|
|
$query ="";
|
|||
|
|
$first_load =1;
|
|||
|
|
}
|
|||
|
|
/**
|
|||
|
|
* ************* GET DATA FROM DB********************
|
|||
|
|
*/
|
|||
|
|
$rows = $db->query ( $query );
|
|||
|
|
|
|||
|
|
// prepare data for Smarty
|
|||
|
|
|
|||
|
|
while ( $r = $db->fetchByAssoc ( $rows ) ) {
|
|||
|
|
$row = array ();
|
|||
|
|
$row ['docname'] = $r ['docname'];
|
|||
|
|
$row ['docdate'] = $r ['docdate'];
|
|||
|
|
$row ['docid'] = $r ['docid'];
|
|||
|
|
|
|||
|
|
$row ['docdateentered'] = $r ['docdateentered'];
|
|||
|
|
$row ['doccategory'] = $app_list_strings['document_category_dom'][$r ['doccategory']];
|
|||
|
|
$row ['docdes'] = $r ['docdes'];
|
|||
|
|
$row ['docwartosc'] = number_format($r ['docwartosc'], 2, ",", ".");
|
|||
|
|
$row ['username'] = $r ['username'];
|
|||
|
|
$row ['userlastname'] = $r ['userlastname'];
|
|||
|
|
$suma +=$r ['docwartosc'];
|
|||
|
|
|
|||
|
|
// Wczytywanie raportów
|
|||
|
|
$queryraport = "SELECT
|
|||
|
|
accepted
|
|||
|
|
FROM
|
|||
|
|
documents_user
|
|||
|
|
WHERE
|
|||
|
|
document_id = '".$row['docid']."'";
|
|||
|
|
$tmp = $db->query ( $queryraport );
|
|||
|
|
if($tmp->num_rows == 0){
|
|||
|
|
$row['docreport'] = 0;
|
|||
|
|
}else{
|
|||
|
|
$row['docreport'] = 1;
|
|||
|
|
}
|
|||
|
|
$data [] = $row;
|
|||
|
|
}
|
|||
|
|
/**
|
|||
|
|
* ******************** SMARTY **********************
|
|||
|
|
*/
|
|||
|
|
// create & execute smarty
|
|||
|
|
$smarty = new Sugar_Smarty ();
|
|||
|
|
global $mod_strings;
|
|||
|
|
$smarty -> assign('MOD', $mod_strings);
|
|||
|
|
$smarty -> assign('DATA', $data);
|
|||
|
|
$smarty -> assign('SUMA',number_format($suma, 2, ",", "."));
|
|||
|
|
$smarty -> assign('date_from', $date_from);
|
|||
|
|
$smarty -> assign('date_to', $date_to );
|
|||
|
|
$smarty -> assign('dateFormat', $Calendar_daFormat);
|
|||
|
|
$smarty -> assign('doc_name', $doc_name);
|
|||
|
|
$smarty -> assign('first_load', $first_load);
|
|||
|
|
$smarty -> assign('PARENT_TYPE_LIST', $app_list_strings['parent_type_display2']);
|
|||
|
|
$smarty -> assign('category', $app_list_strings['document_category_dom']);
|
|||
|
|
$smarty -> assign('category_selected', $category_id);
|
|||
|
|
$smarty -> assign('status', $status);
|
|||
|
|
$smarty -> assign('statusy', array(
|
|||
|
|
'' => '',
|
|||
|
|
'0' => 'Oczekujące',
|
|||
|
|
'1' => 'Zaakceptowane',
|
|||
|
|
'2' => 'Odrzucone')
|
|||
|
|
);
|
|||
|
|
echo $smarty->display ( 'modules/EcmReports/tpls/ReportAcceptance.tpl' );
|
|||
|
|
?>
|