Add php files
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
//ini_set('display_errors',1);
|
||||
require_once ('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
|
||||
global $mod_strings, $app_list_strings;
|
||||
|
||||
$accountName = null;
|
||||
$accountId = null;
|
||||
if(isSet($_REQUEST["accountName"])){
|
||||
$accountName = $_REQUEST["accountName"];
|
||||
}
|
||||
if(isSet($_REQUEST["accountId"])){
|
||||
$accountId = $_REQUEST["accountId"];
|
||||
}
|
||||
$to_pdf = false;
|
||||
if(isSet($_GET ['to_pdf']) && $_GET ['to_pdf'] =='1'){
|
||||
$to_pdf = true;
|
||||
}
|
||||
|
||||
if (isset($accountId) && $accountId!='') {
|
||||
$where['accountId'] = $accountId;
|
||||
} else if (!isset($accountId) && isset($accountName) && strlen($accountName) > 0) {
|
||||
$where['accountName'] = $accountName;
|
||||
}
|
||||
|
||||
try {
|
||||
$tmp = new DateTime(date('Y-m-31'));
|
||||
$tmp2 = new DateTime(date('Y-m-01'));
|
||||
$tmp2->sub(new DateInterval('P1Y'));
|
||||
$where['register_date_to'] = $tmp->format('Y-m-d');
|
||||
$where['register_date_from'] = $tmp2->format('Y-m-d');
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$data = AnalysisEcmQuote($where);
|
||||
$rows = array();
|
||||
if(count($data)>0){
|
||||
foreach ($data as $key => $value) {
|
||||
$rows['created'][] = $value['created'];
|
||||
$rows['accepted'][] = $value['accepted'];
|
||||
$rows['not_accepted'][] = $value['not_accepted'];
|
||||
}
|
||||
}
|
||||
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("DATA", $data);
|
||||
$smarty->assign("ROWS", $rows);
|
||||
|
||||
$smarty->assign("accountName", $accountName);
|
||||
$smarty->assign("accountId", $accountId);
|
||||
|
||||
if ($to_pdf) {
|
||||
$output = $smarty->fetch('modules/EcmReports/tpls/PDF/AnalysisProductSale.tpl');
|
||||
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
$p = new mPDF('', 'A4', NULL, 'helvetica', 10, 10, 10, 10, 5, 5);
|
||||
$p->writeHTML($output);
|
||||
$p->Output('RaportSprzedazy.pdf', 'I');
|
||||
} else {
|
||||
echo $smarty->display('modules/EcmReports/tpls/AnalysisEcmQuote.tpl');
|
||||
}
|
||||
|
||||
function AnalysisEcmQuote($where) {
|
||||
global $db;
|
||||
$query = "SELECT status, register_date FROM ecmquotes WHERE deleted=0 ";
|
||||
//die(1);
|
||||
if (isset($where) && is_array($where) && count($where) > 0) {
|
||||
|
||||
$wherereturn = array();
|
||||
foreach ($where as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'register_date_from':
|
||||
$wherereturn[] = "register_date>='" . $value . "'";
|
||||
break;
|
||||
case 'register_date_to':
|
||||
$wherereturn[] = "register_date<='" . $value . "'";
|
||||
break;
|
||||
case 'accountName':
|
||||
$wherereturn[] = "parent_name LIKE '%" . trim($value) . "%'";
|
||||
$wherereturn[] = "parent_type ='Accounts'";
|
||||
break;
|
||||
case 'accountId':
|
||||
$wherereturn[] = "parent_id = '" . trim($value) . "'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count($wherereturn) > 0) {
|
||||
$query .= " AND " . implode(" AND ", $wherereturn);
|
||||
}
|
||||
}
|
||||
$query .= " ORDER BY register_date";
|
||||
$result = $db->query($query);
|
||||
$return = array();
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$return[substr($row['register_date'], 0, 7)][$row['status']] += 1;
|
||||
}
|
||||
} else {
|
||||
$return = NULL;
|
||||
}
|
||||
|
||||
if(count($return)<12){
|
||||
try {
|
||||
$currentDate = new DateTime(date('Y-m-01'));
|
||||
$date = new DateTime(date('Y-m-01'));
|
||||
$date->sub(new DateInterval('P1Y'));
|
||||
$register_date_fill = $date->format('Y-m');
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
exit(1);
|
||||
}
|
||||
while(count($return)<12){
|
||||
if(!isset($return[$register_date_fill])){
|
||||
$return[$register_date_fill]['total_purchase'] = 0;
|
||||
$return[$register_date_fill]['total_netto'] = 0;
|
||||
}
|
||||
$date->add(new DateInterval('P1M'));
|
||||
$register_date_fill = $date->format('Y-m');
|
||||
}
|
||||
}
|
||||
|
||||
ksort($return);
|
||||
$formated_return;
|
||||
foreach ($return as $data => $row){
|
||||
$split = split("-",$data);
|
||||
$formated_return[$split[1] .".".$split[0]] = $row;
|
||||
}
|
||||
|
||||
return $formated_return;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
require_once ('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
|
||||
global $mod_strings, $app_list_strings;
|
||||
|
||||
$productCategoryList = getProductCategoryList();
|
||||
|
||||
$accountName = $_REQUEST["accountName"];
|
||||
$accountId = $_REQUEST["accountId"];
|
||||
|
||||
$productName = $_REQUEST["productName"];
|
||||
$productId = $_REQUEST["productId"];
|
||||
if (isset($productId) && $productId != '') {
|
||||
$where['productId'] = $productId;
|
||||
} else if (!isset($productId) && isset($productName) && strlen($productName) > 0) {
|
||||
$where['productName'] = $productName;
|
||||
}
|
||||
|
||||
if (isset($accountId) && $accountId!='') {
|
||||
$where['accountId'] = $accountId;
|
||||
} else if (!isset($accountId) && isset($accountName) && strlen($accountName) > 0) {
|
||||
$where['accountName'] = $accountName;
|
||||
}
|
||||
|
||||
try {
|
||||
$tmp = new DateTime(date('Y-m-31'));
|
||||
$tmp2 = new DateTime(date('Y-m-01'));
|
||||
$tmp2->sub(new DateInterval('P1Y'));
|
||||
$where['register_date_to'] = $tmp->format('Y-m-d');
|
||||
$where['register_date_from'] = $tmp2->format('Y-m-d');
|
||||
// $where['register_date_to'] = '2015-07-31';
|
||||
// $where['register_date_from'] = '2015-07-01';
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//$where['type'] = 'correct';
|
||||
//$where['type'] = 'normal';
|
||||
$where['deleted'] = 0;
|
||||
$where['canceled'] = 0;
|
||||
$data = AnalysisProductSale($where);
|
||||
$rows = array();
|
||||
foreach ($data as $key => $value) {
|
||||
$rows['netto'][] = $value['total_netto'];
|
||||
// $rows['total_brutto'][] = $value['total_brutto'];
|
||||
$rows['kupno'][] = $value['total_purchase'];
|
||||
$rows['marza'][] = $value['total_netto'] - $value['total_purchase'];
|
||||
$rows['marzaprocent'][] = (($value['total_netto'] - $value['total_purchase']) * 100) / $value['total_netto'];
|
||||
}
|
||||
|
||||
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("DATA", $data);
|
||||
$smarty->assign("ROWS", $rows);
|
||||
|
||||
$smarty->assign("productCategoryList", $productCategoryList);
|
||||
$smarty->assign("productCategorySelected", $productCategorySelected);
|
||||
|
||||
$smarty->assign("accountName", $accountName);
|
||||
$smarty->assign("accountId", $accountId);
|
||||
|
||||
$smarty->assign("productName", $productName);
|
||||
$smarty->assign("productId", $productId);
|
||||
|
||||
|
||||
if ($_GET ['to_pdf'] == '1') {
|
||||
$output = $smarty->fetch('modules/EcmReports/tpls/PDF/AnalysisProductSale.tpl');
|
||||
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
$p = new mPDF('', 'A4', NULL, 'helvetica', 10, 10, 10, 10, 5, 5);
|
||||
$p->writeHTML($output);
|
||||
$p->Output('RaportSprzedazy.pdf', 'I');
|
||||
} else {
|
||||
echo $smarty->display('modules/EcmReports/tpls/AnalysisProductSale.tpl');
|
||||
}
|
||||
|
||||
function AnalysisProductSale($where) {
|
||||
global $db;
|
||||
$query = "SELECT p.quantity_corrected, p.total_brutto_corrected, p.total_netto_corrected ,p.ecminvoiceout_id, p.ecmproduct_id, p.code, p.name, p.total_netto, p.total_brutto, p.price_purchase, p.quantity , i.register_date, i.type, i.currency_value, i.currency_value_nbp, i.currency_id FROM ecminvoiceoutitems p, ecminvoiceouts i WHERE p.ecminvoiceout_id = i.id";
|
||||
//die(1);
|
||||
if (isset($where) && is_array($where) && count($where) > 0) {
|
||||
|
||||
$wherereturn = array();
|
||||
foreach ($where as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'register_date_from':
|
||||
$wherereturn[] = "i.register_date>='" . $value . "'";
|
||||
break;
|
||||
case 'register_date_to':
|
||||
$wherereturn[] = "i.register_date<='" . $value . "'";
|
||||
break;
|
||||
case 'accountName':
|
||||
$wherereturn[] = "i.parent_name LIKE '%" . trim($value) . "%'";
|
||||
$wherereturn[] = "i.parent_type ='Accounts'";
|
||||
break;
|
||||
case 'productName':
|
||||
$wherereturn[] = "p.name LIKE '%" . trim($value) . "%'";
|
||||
break;
|
||||
case 'productId':
|
||||
$wherereturn[] = "p.ecmproduct_id = '" . trim($value) . "'";
|
||||
break;
|
||||
case 'accountId':
|
||||
$wherereturn[] = "i.parent_id = '" . trim($value) . "'";
|
||||
break;
|
||||
default:
|
||||
$wherereturn[] = "i." . $key . " = '" . $value . "'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (count($wherereturn) > 0) {
|
||||
$query .= " AND " . implode(" AND ", $wherereturn);
|
||||
}
|
||||
}
|
||||
$query .= " ORDER BY i.register_date";
|
||||
//echo $query;
|
||||
$result = $db->query($query);
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$currency = 1;
|
||||
if($row['type']!='K'){
|
||||
if($row['currency_value']!=''&& $row['currency_value']!='0'){
|
||||
$currency = $row['currency_value'];
|
||||
}elseif($row['currency_value_nbp']!=''){
|
||||
$currency = $row['currency_value_nbp'];
|
||||
}
|
||||
}
|
||||
if($row['type']=='normal'){
|
||||
$return[substr($row['register_date'], 0, 7)]['total_purchase'] += round($row['price_purchase']* $row['quantity'],2);
|
||||
$return[substr($row['register_date'], 0, 7)]['total_netto'] += $row['total_netto']* $currency;
|
||||
}else{
|
||||
$return[substr($row['register_date'], 0, 7)]['total_purchase'] += round($row['price_purchase'] * $row['quantity_corrected'] ,2);
|
||||
$return[substr($row['register_date'], 0, 7)]['total_netto'] += $row['total_netto_corrected']* $currency;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$return = NULL;
|
||||
}
|
||||
|
||||
if(count($return)<12){
|
||||
try {
|
||||
$currentDate = new DateTime(date('Y-m-01'));
|
||||
$date = new DateTime(date('Y-m-01'));
|
||||
$date->sub(new DateInterval('P1Y'));
|
||||
$register_date_fill = $date->format('Y-m');
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
exit(1);
|
||||
}
|
||||
while(count($return)<12){
|
||||
if(!isset($return[$register_date_fill])){
|
||||
$return[$register_date_fill]['total_purchase'] = 0;
|
||||
$return[$register_date_fill]['total_netto'] = 0;
|
||||
}
|
||||
$date->add(new DateInterval('P1M'));
|
||||
$register_date_fill = $date->format('Y-m');
|
||||
}
|
||||
}
|
||||
|
||||
ksort($return);
|
||||
$formated_return;
|
||||
foreach ($return as $data => $row){
|
||||
$split = split("-",$data);
|
||||
$formated_return[$split[1] .".".$split[0]] = $row;
|
||||
}
|
||||
|
||||
return $formated_return;
|
||||
}
|
||||
|
||||
function getProductCategoryList() {
|
||||
global $db;
|
||||
$resultArray = NULL;
|
||||
$query = "SELECT id, name FROM ecmproductcategories WHERE deleted=0 ORDER BY name, date_entered";
|
||||
$result = $db->query($query);
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$resultArray[$row['id']] = $row['name'];
|
||||
};
|
||||
}
|
||||
return $resultArray;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
|
||||
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
|
||||
|
||||
require_once('modules/EcmReports/EcmReport.php');
|
||||
require_once('modules/EcmReports/Forms.php');
|
||||
require_once ('include/time.php');
|
||||
require_once('include/json_config.php');
|
||||
|
||||
$json_config = new json_config();
|
||||
|
||||
$focus = new EcmReport();
|
||||
|
||||
if(isset($_REQUEST['record']))$focus->retrieve($_REQUEST['record']);
|
||||
|
||||
require_once('include/MVC/View/SugarView.php');
|
||||
|
||||
if(file_exists('modules/EcmReports/views/view.detail.php')) {
|
||||
require_once('modules/EcmReports/views/view.detail.php');
|
||||
$detail = new EcmReport();
|
||||
}
|
||||
else{
|
||||
require_once('include/MVC/View/views/view.detail.php');
|
||||
$detail = new ViewDetail();
|
||||
$detail->ss = new Sugar_Smarty();
|
||||
$detail->module = 'EcmReports';
|
||||
}
|
||||
|
||||
global $app_list_strings;
|
||||
|
||||
$detail->bean = $focus;
|
||||
$detail->preDisplay();
|
||||
|
||||
echo $detail->display();
|
||||
?>
|
||||
161
modules/var/www/html/system/modules/EcmReports/EcmReport.php
Normal file
161
modules/var/www/html/system/modules/EcmReports/EcmReport.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: TODO: To be written.
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
require_once('data/SugarBean.php');
|
||||
require_once('include/utils.php');
|
||||
|
||||
class EcmReport extends SugarBean {
|
||||
var $field_name_map = array();
|
||||
|
||||
var $id;
|
||||
var $date_entered;
|
||||
var $date_modified;
|
||||
var $modified_user_id;
|
||||
var $assigned_user_id;
|
||||
var $name;
|
||||
var $value;
|
||||
|
||||
var $module_dir = 'EcmReports';
|
||||
var $table_name = "ecmreports";
|
||||
var $object_name = "EcmReport";
|
||||
|
||||
var $new_schema = true;
|
||||
|
||||
var $additional_column_fields = array('assigned_user_name', 'assigned_user_id');
|
||||
|
||||
function EcmReport() {
|
||||
parent::SugarBean();
|
||||
$this->setupCustomFields('EcmReports');
|
||||
foreach($this->field_defs as $field){
|
||||
$this->field_name_map[$field['name']] = $field;
|
||||
}
|
||||
}
|
||||
function get_summary_text(){
|
||||
return $this->name;
|
||||
}
|
||||
function create_list_query($order_by, $where, $show_deleted = 0){
|
||||
$custom_join = $this->custom_fields->getJOIN();
|
||||
$query ="SELECT ";
|
||||
$query.="ecmreports.*,users.user_name as assigned_user_name";
|
||||
if($custom_join)$query.=$custom_join['select'];
|
||||
$query.=" FROM ecmreports ";
|
||||
$query.="LEFT JOIN users ON ecmreports.assigned_user_id=users.id";
|
||||
$query.=" ";
|
||||
if($custom_join)$query.=$custom_join['join'];
|
||||
$where_auto='1=1';
|
||||
if($show_deleted==0)$where_auto=" $this->table_name.deleted=0 ";
|
||||
elseif($show_deleted==1)$where_auto=" $this->table_name.deleted=1 ";
|
||||
if($where!="")$query.="where $where AND ".$where_auto;
|
||||
else $query.="where ".$where_auto;
|
||||
if(substr_count($order_by,'.')>0)$query .= " ORDER BY $order_by";
|
||||
elseif($order_by != "")$query .= " ORDER BY $order_by";
|
||||
else $query .= " ORDER BY ecmreports.name";
|
||||
return $query;
|
||||
}
|
||||
function create_export_query($order_by,$where){
|
||||
$custom_join = $this->custom_fields->getJOIN();
|
||||
$query ="SELECT ";
|
||||
$query.="ecmreports.*,users.user_name as assigned_user_name";
|
||||
if($custom_join)$query.=$custom_join['select'];
|
||||
$query.=" FROM ecmreports ";
|
||||
$query.="LEFT JOIN users ON ecmreports.assigned_user_id=users.id";
|
||||
$query.=" ";
|
||||
if($custom_join)$query.=$custom_join['join'];
|
||||
$where_auto='1=1';
|
||||
if($show_deleted==0)$where_auto=" $this->table_name.deleted=0 ";
|
||||
elseif($show_deleted==1)$where_auto=" $this->table_name.deleted=1 ";
|
||||
if($where!="")$query.="where $where AND ".$where_auto;
|
||||
else $query.="where ".$where_auto;
|
||||
if(substr_count($order_by,'.')>0)$query .= " ORDER BY $order_by";
|
||||
elseif($order_by != "")$query .= " ORDER BY $order_by";
|
||||
else $query .= " ORDER BY ecmreports.name";
|
||||
return $query;
|
||||
}
|
||||
function fill_in_additional_list_fields(){
|
||||
}
|
||||
|
||||
function fill_in_additional_detail_fields(){
|
||||
parent::fill_in_additional_detail_fields();
|
||||
}
|
||||
function get_list_view_data(){
|
||||
global $current_language;
|
||||
$the_array=parent::get_list_view_data();
|
||||
$app_list_strings=return_app_list_strings_language($current_language);
|
||||
$mod_strings=return_module_language($current_language,'EcmReports');
|
||||
|
||||
$the_array['NAME']=(($this->name == "") ? "<em>blank</em>" : $this->name);
|
||||
$the_array['ENCODED_NAME']=$this->name;
|
||||
return $the_array;
|
||||
}
|
||||
function build_generic_where_clause($the_query_string){
|
||||
$where_clauses=array();
|
||||
$the_query_string=PearDatabase::quote(from_html($the_query_string));
|
||||
array_push($where_clauses,"ecmreports.name like '$the_query_string%'");
|
||||
|
||||
$the_where="";
|
||||
foreach($where_clauses as $clause){
|
||||
if($the_where!="")$the_where.=" or ";
|
||||
$the_where.=$clause;
|
||||
}
|
||||
return $the_where;
|
||||
}
|
||||
function set_notification_body($xtpl,$ecmreport)
|
||||
{
|
||||
global $mod_strings,$app_list_strings;
|
||||
$xtpl->assign("ECMREPORT_SUBJECT",$ecmreport->name);
|
||||
return $xtpl;
|
||||
}
|
||||
|
||||
function bean_implements($interface){
|
||||
switch($interface){
|
||||
case 'ACL':return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function save($check_notify=FALSE){
|
||||
return parent::save($check_notify);
|
||||
}
|
||||
}
|
||||
?>
|
||||
358
modules/var/www/html/system/modules/EcmReports/Kartoteka.php
Normal file
358
modules/var/www/html/system/modules/EcmReports/Kartoteka.php
Normal file
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
// partie
|
||||
include 'EcmConfig.php';
|
||||
|
||||
ini_set('memory_limit','-1');
|
||||
ini_set('max_execution_time','-1');
|
||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
||||
die ( 'Not A Valid Entry Point' );
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
$doc_name=array('EcmStockDocInsideIns'=>'PW','EcmStockDocMoves'=>'MM','EcmStockDocCorrects'=>'KS','EcmStockDocIns'=>'PZ','EcmStockDocOuts'=>'WZ','EcmStockDocInsideOuts'=>'RW','EcmInvoiceOuts'=>"FK",'EcmInvoiceOuts2'=>"KF");
|
||||
/*
|
||||
* Magazyny
|
||||
*/
|
||||
$datastocks = array ();
|
||||
$users = array ();
|
||||
$queryStocks = "SELECT
|
||||
name,
|
||||
id
|
||||
FROM ecmstocks
|
||||
where deleted= 0";
|
||||
$rowsStocks = $db->query ( $queryStocks );
|
||||
$s=array();
|
||||
while ( $rowStocks = $db->fetchByAssoc ( $rowsStocks ) ) {
|
||||
$stocks ["name"] = $rowStocks ["name"];
|
||||
$stocks ["id"] = $rowStocks ["id"];
|
||||
$datastocks [] = $stocks;
|
||||
$s[$stocks ["id"]]['name']=$stocks ["name"];
|
||||
}
|
||||
if($_GET['date_from']==''){
|
||||
$_GET['date_from']=date('01.m.Y');
|
||||
} else {
|
||||
$date_from=date('Y-m-d 00:00:01',strtotime($_GET['date_from']));
|
||||
}
|
||||
if( $_GET['date_to']==''){
|
||||
$_GET['date_to']=date('t.m.Y');
|
||||
} else {
|
||||
$date_to=date('Y-m-d 23:59:59',strtotime($_GET['date_to']));
|
||||
}
|
||||
|
||||
/*
|
||||
* Dodatkowe parametry do zapytania
|
||||
*/
|
||||
if ($_GET ['selectStock'] != "")
|
||||
$add_where .= " AND stock_id = '" . $_GET ["selectStock"] . "' ";
|
||||
|
||||
if ($_GET ['selectProductActive'] != ""){
|
||||
$where= " WHERE product_active = '" . $_GET ["selectProductActive"] . "' ";
|
||||
} else {
|
||||
$where='';
|
||||
}
|
||||
$_GET['selectShowEmpty']=1;
|
||||
$r1 = $db->query("SELECT id, name, code, unit_id FROM ecmproducts ".$where." ORDER BY name ASC");
|
||||
|
||||
//var_dump("SELECT id, name, code, unit_id FROM ecmproducts ".$where." ORDER BY name ASC");
|
||||
$docs = array();
|
||||
$i=0;
|
||||
$total_quantity_old=0;
|
||||
$total_value_old=0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query(
|
||||
"SELECT * FROM ecmstockoperations WHERE product_id='" . $tmp2['id'] . "' ".$add_where." AND in_id IS NULL AND type=0 AND date_entered <='".$date_from."'");
|
||||
$l = 0;
|
||||
$i=$tmp2['id'];
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id']=$app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id']=$tmp2['id'];
|
||||
$docs[$i]['product_name']=$tmp2['name'];
|
||||
$docs[$i]['product_code']=$tmp2['code'];
|
||||
$docs[$i]['total_quantity_old']=0;
|
||||
$docs[$i]['total_price_old']=0;
|
||||
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
|
||||
$ii = $db->query(
|
||||
"select * from ecmstockoperations where in_id='" . $tmp['id'] .
|
||||
"' and type=1 and date_entered <='".$date_from."'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
|
||||
$quantity_tmp -= $tmp2['quantity'];
|
||||
}
|
||||
if($quantity_tmp==0){
|
||||
$db->query("update ecmstockoperations set used=1 where id='".$tmp['id']."'");
|
||||
continue;
|
||||
}
|
||||
$doc['quantity'] = $quantity_tmp;
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_type2'] = $tmp['parent_type'];
|
||||
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity_old+=$doc['quantity'];
|
||||
$total_value_old+=round($doc['quantity']*$tmp['price'],2);
|
||||
//$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_old']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i]['total_quantity_old']+=($doc['quantity']);
|
||||
} else {
|
||||
// dla całych
|
||||
$doc['quantity'] = $tmp['quantity'];
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity_old+=$doc['quantity'];
|
||||
$total_value_old+=round($doc['quantity']*$tmp['price'],2);
|
||||
// $docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_old']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i]['total_quantity_old']+=($doc['quantity']);
|
||||
|
||||
}
|
||||
|
||||
if ($r->num_rows > 1) {
|
||||
$docs[$i]['price']=$docs[$i]['total_price_old']/$docs[$i]['total_quantity_old'];
|
||||
$docs[$i]['parent_name']='';
|
||||
$docs[$i]['parent_type']='';
|
||||
} if ($r->num_rows < 2 ){
|
||||
$docs[$i]['price']=$tmp['price'];
|
||||
|
||||
$doc[$i]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i]['parent_id'] = $tmp['parent_id'];
|
||||
$docs[$i]['parent_name']=$tmp['parent_name'];
|
||||
// $docs[$i-1]['date_entered'] = $n->register_date;
|
||||
$docs[$i]['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
}else {
|
||||
$docs[$i]['price']=$docs[$i]['total_price_old']/$docs[$i]['total_quantity_old'];
|
||||
$docs[$i]['parent_name']='';
|
||||
$docs[$i]['parent_type']='';
|
||||
}
|
||||
|
||||
}
|
||||
if( $docs[$i]['total_quantity_old']==0 && $_GET['selectShowEmpty']!='')unset($docs[$i]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts ".$where." order by name asc");
|
||||
|
||||
$i=0;
|
||||
$total_quantity_now=0;
|
||||
$total_value_now=0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query(
|
||||
"select * from ecmstockoperations where
|
||||
product_id='" . $tmp2['id'] . "'
|
||||
".$add_where."
|
||||
and in_id is null and used=0 and type=0 and date_entered <='".$date_to."'");
|
||||
$i=$tmp2['id'];
|
||||
$l = 0;
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id']=$app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id']=$tmp2['id'];
|
||||
$docs[$i]['product_name']=$tmp2['name'];
|
||||
$docs[$i]['product_code']=$tmp2['code'];
|
||||
$docs[$i]['total_quantity_now']=0;
|
||||
$docs[$i]['total_price_now']=0;
|
||||
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
|
||||
$ii = $db->query(
|
||||
"select * from ecmstockoperations where in_id='" . $tmp['id'] .
|
||||
"' and type=1 and date_entered <='".$date_to."'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
|
||||
$quantity_tmp -= $tmp2['quantity'];
|
||||
}
|
||||
if($quantity_tmp==0){
|
||||
$db->query("update ecmstockoperations set used=1 where id='".$tmp['id']."'");
|
||||
continue;
|
||||
}
|
||||
$doc['quantity'] = $quantity_tmp;
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_type2'] = $tmp['parent_type'];
|
||||
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity_now+=$doc['quantity'];
|
||||
$total_value_now+=round($doc['quantity']*$tmp['price'],2);
|
||||
//$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_now']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i]['total_quantity_now']+=($doc['quantity']);
|
||||
} else {
|
||||
// dla całych
|
||||
$doc['quantity'] = $tmp['quantity'];
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity_now+=$doc['quantity'];
|
||||
$total_value_now+=round($doc['quantity']*$tmp['price'],2);
|
||||
// $docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_now']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i]['total_quantity_now']+=($doc['quantity']);
|
||||
|
||||
}
|
||||
|
||||
if ($r->num_rows > 1) {
|
||||
$docs[$i]['price']=$docs[$i]['total_price_now']/$docs[$i]['total_quantity_now'];
|
||||
$docs[$i]['parent_name']='';
|
||||
$docs[$i]['parent_type']='';
|
||||
} if ($r->num_rows < 2 ){
|
||||
$docs[$i]['price']=$tmp['price'];
|
||||
|
||||
$doc[$i]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i]['parent_id'] = $tmp['parent_id'];
|
||||
$docs[$i]['parent_name']=$tmp['parent_name'];
|
||||
// $docs[$i-1]['date_entered'] = $n->register_date;
|
||||
$docs[$i]['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
}else {
|
||||
$docs[$i]['price']=$docs[$i]['total_price_now']/$docs[$i]['total_quantity_now'];
|
||||
$docs[$i]['parent_name']='';
|
||||
$docs[$i]['parent_type']='';
|
||||
}
|
||||
|
||||
}
|
||||
if( $docs[$i]['total_quantity_now']==0 && $_GET['selectShowEmpty']!='')unset($docs[$i]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts ".$where." order by name asc");
|
||||
|
||||
$i=0;
|
||||
$przychod_w=0;
|
||||
$przychod_q=0;
|
||||
$rozchod_q=0;
|
||||
$doc=array();
|
||||
$rozchod_w=0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query(
|
||||
"select * from ecmstockoperations where
|
||||
product_id='" . $tmp2['id'] . "'
|
||||
".$add_where."
|
||||
and in_id is null and type=0 and date_entered <='".$date_to."' and date_entered >='".$date_from."'");
|
||||
$i=$tmp2['id'];
|
||||
$l = 0;
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id']=$app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id']=$tmp2['id'];
|
||||
$docs[$i]['product_name']=$tmp2['name'];
|
||||
$docs[$i]['product_code']=$tmp2['code'];
|
||||
$docs[$i]['rozchod_q']=0;
|
||||
$docs[$i]['rozchod_w']=0;
|
||||
$docs[$i]['przychod_q']=0;
|
||||
$docs[$i]['przychod_w']=0;
|
||||
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
$module=substr($tmp['parent_type'], 0, -1);
|
||||
|
||||
$doc2 = new $module();
|
||||
$doc2->retrieve($tmp['parent_id']);
|
||||
|
||||
$docs[$i]['przychod_w']+=($tmp['quantity']*$tmp['price'] );
|
||||
$docs[$i]['przychod_q']+=($tmp['quantity']);
|
||||
$przychod_w+=($tmp['quantity']*$tmp['price'] );;
|
||||
$przychod_q+=($tmp['quantity']);
|
||||
if($doc2->type=='correct'){
|
||||
$doc[$tmp['type']]['EcmInvoiceOuts2']+=($tmp['quantity']*$tmp['price'] );
|
||||
} else {
|
||||
$doc[$tmp['type']][$tmp['parent_type']]+=($tmp['quantity']*$tmp['price'] );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$ii = $db->query(
|
||||
"select * from ecmstockoperations where product_id='" . $tmp2['id'] .
|
||||
"' and type=1 and date_entered <='".$date_to."' ".$add_where." and date_entered >='".$date_from."'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
$docs[$i]['rozchod_w']+=($tmp2['quantity']*$tmp2['price'] );
|
||||
$docs[$i]['rozchod_q']+=($tmp2['quantity']);
|
||||
$rozchod_w+=($tmp2['quantity']*$tmp2['price'] );
|
||||
$rozchod_q+=($tmp2['quantity']);
|
||||
$doc[$tmp2['type']][$tmp2['parent_type']]+=($tmp2['quantity']*$tmp2['price'] );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// create & execute smarty
|
||||
$smarty = new Sugar_Smarty ();
|
||||
global $mod_strings;
|
||||
$smarty->assign ( "MOD", $mod_strings );
|
||||
$smarty->assign ( "DATA", $doc );
|
||||
$smarty->assign ( "doc_name", $doc_name );
|
||||
$smarty->assign ( "date_from", $_GET['date_from'] );
|
||||
$smarty->assign ( "date_to", $_GET['date_to'] );
|
||||
$smarty->assign ( "TOTAL_VALUE_OLD", $total_value_old );
|
||||
$smarty->assign ( "TOTAL_QUANTITY_OLD", $total_quantity_old );
|
||||
$smarty->assign ( "TOTAL_VALUE_NOW", $total_value_now );
|
||||
$smarty->assign ( "TOTAL_QUANTITY_NOW", $total_quantity_now );
|
||||
$smarty->assign ( "rozchod_w", $rozchod_w );
|
||||
$smarty->assign ( "rozchod_q", $rozchod_q );
|
||||
$smarty->assign ( "przychod_w", $przychod_w );
|
||||
$smarty->assign ( "przychod_q", $przychod_q );
|
||||
$smarty->assign ( "CONSIGNMENTS",$EcmConfig['consignments']);
|
||||
$smarty->assign ( "STOCKS", $datastocks );
|
||||
$smarty->assign ( "selectStock", $_GET ["selectStock"]);
|
||||
$smarty->assign ( "selectProductActive", $_GET ["selectProductActive"] );
|
||||
$smarty->assign ( "selectProductEol", $_GET ["selectProductEol"] );
|
||||
$smarty->assign ( "selectShowEmpty", $_GET ["selectShowEmpty"] );
|
||||
|
||||
|
||||
// Eksport do PDF
|
||||
if( $_GET['toPDF'] == '1' ) {
|
||||
$output = $smarty->fetch( 'modules/EcmReports/tpls/PDF//Kartoteka.tpl' );
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
unset($smarty);
|
||||
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 25, 10, 5, 5 );
|
||||
$p->setFooter('Strona {PAGENO} z {nbpg}');
|
||||
$comp = new EcmSysInfo();
|
||||
$p->SetHTMLHeader('<p style="text-align:left;font-size: 10px;">'.$comp->name.'<br>
|
||||
Kartoteka ruchu towarów - Podsumowanie<br>Data wydruku: '.date("d.m.Y").'<br>Stan magazynowy za okres: '.$_GET['date_from'].' - '.$_GET['date_to'].'<br>Magazyn: '.$s[$_GET ["selectStock"]]['name']. '<br>Strona {PAGENO} z {nbpg}</p>');
|
||||
//$p->setTitle($mod_strings["LBL_REPORT_STOCKS_DOCS"]);
|
||||
//echo $output;
|
||||
$p->writeHTML( $output );
|
||||
|
||||
$p->Output ();
|
||||
} else {
|
||||
$smarty->display ( 'modules/EcmReports/tpls/Kartoteka.tpl' );
|
||||
}
|
||||
|
||||
?>
|
||||
67
modules/var/www/html/system/modules/EcmReports/Menu.php
Normal file
67
modules/var/www/html/system/modules/EcmReports/Menu.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: TODO To be written.
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
|
||||
global $mod_strings;
|
||||
|
||||
/*
|
||||
* !!!! Menu dla tego modułu jest sztywno wpisane w _headerModuleList.tpl szablonu
|
||||
* -_- boruta jak chuj krzychu!
|
||||
*/
|
||||
|
||||
/*if(ACLController::checkAccess('EcmReports', 'list', true))
|
||||
$module_menu[]=array("index.php?module=EcmReports&action=ReportStocks&return_module=EcmReports&return_action=DetailView", "Raport stanów magazynowych","EcmReports", 'EcmReports');
|
||||
if(ACLController::checkAccess('EcmReports', 'list', true))
|
||||
$module_menu[]=array("index.php?module=EcmReports&action=ReportSales&return_module=EcmReports&return_action=DetailView", "Raport sprzadaży z podziałem na kategorie","EcmReports", 'EcmReports');
|
||||
if(ACLController::checkAccess('EcmReports', 'list', true))
|
||||
$module_menu[]=array("index.php?module=EcmReports&action=ReportSalesByContractor&return_module=EcmReports&return_action=DetailView", "Raport sprzadaży z podziałem na kontrahentów","EcmReports", 'EcmReports');
|
||||
if(ACLController::checkAccess('EcmReports', 'list', true))
|
||||
$module_menu[]=array("index.php?module=EcmReports&action=ListDailySales&return_module=EcmReports&return_action=DetailView", "Raport sprzadaży z podziałem na dokumenty","EcmReports", 'EcmReports');
|
||||
if(ACLController::checkAccess('EcmReports', 'list', true))
|
||||
$module_menu[]=array("index.php?module=EcmReports&action=ReportAcceptance&return_module=EcmReports&return_action=DetailView", "Raport akceptacji","EcmReports", 'EcmReports');
|
||||
if(ACLController::checkAccess('EcmReports', 'list', true))
|
||||
$module_menu[]=array("index.php?module=EcmReports&action=ReportValue&return_module=EcmReports&return_action=DetailView", "Raport wartości","EcmReports", 'EcmReports');
|
||||
*/
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
function getStartValues($product_id,$stock,$date_from){
|
||||
$db = $GLOBALS['db'];
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts where id='".$product_id."' ");
|
||||
$docs = array();
|
||||
$i=0;
|
||||
$total_quantity_old=0;
|
||||
$total_value_old=0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
|
||||
$r = $db->query(
|
||||
"select * from ecmstockoperations where
|
||||
product_id='" . $tmp2['id'] . "'
|
||||
and stock_id = '" . $stock . "'
|
||||
and in_id is null and type=0 and date_entered <='".$date_from."'");
|
||||
|
||||
$l = 0;
|
||||
$i=$tmp2['id'];
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id']=$app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['unit_precision']=$app_list_strings['ecmproducts_unit_dom_precision'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id']=$tmp2['id'];
|
||||
$docs[$i]['product_name']=$tmp2['name'];
|
||||
$docs[$i]['product_code']=$tmp2['code'];
|
||||
$docs[$i]['total_quantity_old']=0;
|
||||
$docs[$i]['total_price_old']=0;
|
||||
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
|
||||
$ii = $db->query(
|
||||
"select * from ecmstockoperations where in_id='" . $tmp['id'] .
|
||||
"' and type=1 and date_entered <='".$date_from."'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
|
||||
$quantity_tmp -= $tmp2['quantity'];
|
||||
}
|
||||
if($quantity_tmp==0){
|
||||
$db->query("update ecmstockoperations set used=1 where id='".$tmp['id']."'");
|
||||
continue;
|
||||
}
|
||||
$doc['quantity'] = $quantity_tmp;
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_type2'] = $tmp['parent_type'];
|
||||
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity_old+=$doc['quantity'];
|
||||
$total_value_old+=round($doc['quantity']*$tmp['price'],2);
|
||||
//$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_old']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i]['total_quantity_old']+=($doc['quantity']);
|
||||
} else {
|
||||
|
||||
// dla całych
|
||||
$doc['quantity'] = $tmp['quantity'];
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity_old+=$doc['quantity'];
|
||||
$total_value_old+=round($doc['quantity']*$tmp['price'],2);
|
||||
// $docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_old']+=($doc['quantity']*$tmp['price'] );
|
||||
|
||||
$docs[$i]['total_quantity_old']+=($doc['quantity']);
|
||||
|
||||
}
|
||||
|
||||
if ($r->num_rows > 1) {
|
||||
$docs[$i]['price']=$docs[$i]['total_price_old']/$docs[$i]['total_quantity_old'];
|
||||
$docs[$i]['parent_name']='';
|
||||
$docs[$i]['parent_type']='';
|
||||
} if ($r->num_rows < 2 ){
|
||||
$docs[$i]['price']=$tmp['price'];
|
||||
|
||||
$doc[$i]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i]['parent_id'] = $tmp['parent_id'];
|
||||
$docs[$i]['parent_name']=$tmp['parent_name'];
|
||||
// $docs[$i-1]['date_entered'] = $n->register_date;
|
||||
$docs[$i]['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
}else {
|
||||
$docs[$i]['price']=$docs[$i]['total_price_old']/$docs[$i]['total_quantity_old'];
|
||||
$docs[$i]['parent_name']='';
|
||||
$docs[$i]['parent_type']='';
|
||||
}
|
||||
|
||||
}
|
||||
//if( $docs[$i]['total_quantity_old']==0 && $_GET['selectShowEmpty']!='')unset($docs[$i]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
return array($total_quantity_old,$total_value_old);
|
||||
}
|
||||
|
||||
function getStateAfterOperation($id,$product_id,$stock_id){
|
||||
$nr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select counter from ecmstockoperations where id='".$id."'"));
|
||||
$res=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("
|
||||
select
|
||||
sum(CASE
|
||||
WHEN (type=0)
|
||||
then @t :=+quantity
|
||||
else @t :=-quantity
|
||||
end) as tt
|
||||
,sum(CASE WHEN (type=0) then @t :=+quantity*price else @t :=-quantity*price end) as tt2
|
||||
|
||||
from ecmstockoperations where product_id='".$product_id."' and stock_id='".$stock_id."' and counter <= '".$nr['counter']."'"));
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
function getOperations($product_id,$stock,$date_from,$date_to,$quantity,$val){
|
||||
$db = $GLOBALS['db'];
|
||||
$result=array();
|
||||
$doc_name=array('EcmStockDocInsideIns'=>'PW','EcmStockDocMoves'=>'MM','EcmStockDocCorrects'=>'KS','EcmStockDocIns'=>'PZ','EcmStockDocInsideOuts'=>'RW','EcmStockDocOuts'=>'WZ','EcmInvoiceOuts'=>'FK');
|
||||
$sum['in_quantity']=0;
|
||||
$sum['in_value']=0;
|
||||
$sum['out_quantity']=0;
|
||||
$sum['out_value']=0;
|
||||
$sum['after_quantity']=$quantity;
|
||||
$sum['after_value']=$val;
|
||||
|
||||
$p= new EcmProduct();
|
||||
|
||||
$p->retrieve($product_id);
|
||||
|
||||
$product_name=$p->name;
|
||||
$product_code=$p->code;
|
||||
|
||||
$r1 = $db->query("select id,date_entered,quantity,type,price,parent_type,parent_id from ecmstockoperations where product_id='".$product_id."' and stock_id='".$stock."' and date_entered >='".$date_from."' and date_entered <='".$date_to."' order by date_entered asc");
|
||||
$lp=1;
|
||||
while($dane=$db->fetchByAssoc($r1)){
|
||||
$dane['lp']=$lp;
|
||||
|
||||
$dane['product_name']=$product_name;
|
||||
$dane['product_code']=$product_code;
|
||||
$dane['value']=$dane['quantity']*$dane['price'];
|
||||
$module=substr($dane['parent_type'], 0, -1);
|
||||
|
||||
$doc = new $module();
|
||||
$doc->retrieve($dane['parent_id']);
|
||||
if($doc->type=='correct'){
|
||||
$dane['doc_code']='KF';
|
||||
} else {
|
||||
$dane['doc_code']=$doc_name[$dane['parent_type']];
|
||||
}
|
||||
|
||||
$dane['doc_name']=$doc->document_no;
|
||||
$dane['doc_parent_name']=$doc->parent_name;
|
||||
|
||||
$after=getStateAfterOperation($dane['id'],$product_id,$stock);;
|
||||
|
||||
$dane['after_quantity']=$after['tt'];
|
||||
$dane['after_value']=$after['tt2'];
|
||||
$dane['correct']=$doc->type;
|
||||
|
||||
if($dane['type']==0){
|
||||
if($dane['correct']=='correct'){
|
||||
$sum['out_quantity']-=$dane['quantity'];
|
||||
$sum['out_value']-=$dane['value'];
|
||||
|
||||
$sum['after_quantity']+=$dane['quantity'];
|
||||
$sum['after_value']+=$dane['value'];
|
||||
} else {
|
||||
$sum['in_quantity']+=$dane['quantity'];
|
||||
$sum['in_value']+=$dane['value'];
|
||||
|
||||
$sum['after_quantity']+=$dane['quantity'];
|
||||
$sum['after_value']+=$dane['value'];
|
||||
}
|
||||
|
||||
} else {
|
||||
$sum['out_quantity']+=$dane['quantity'];
|
||||
$sum['out_value']+=$dane['value'];
|
||||
|
||||
$sum['after_quantity']-=$dane['quantity'];
|
||||
$sum['after_value']-=$dane['value'];
|
||||
}
|
||||
if($doc->type=='correct'){
|
||||
$dane['quantity']=$dane['quantity']*-1;
|
||||
$dane['value']=$dane['quantity']*$dane['price'];
|
||||
}
|
||||
$result[]=$dane;
|
||||
$lp++;
|
||||
}
|
||||
|
||||
return array($result,$sum);
|
||||
}
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
|
||||
$datastocks = array ();
|
||||
$users = array ();
|
||||
$queryStocks = "SELECT
|
||||
name,
|
||||
id
|
||||
FROM ecmstocks
|
||||
where deleted= 0";
|
||||
$rowsStocks = $db->query ( $queryStocks );
|
||||
$s=array();
|
||||
while ( $rowStocks = $db->fetchByAssoc ( $rowsStocks ) ) {
|
||||
$stocks ["name"] = $rowStocks ["name"];
|
||||
$stocks ["id"] = $rowStocks ["id"];
|
||||
$datastocks [] = $stocks;
|
||||
$s[$stocks ["id"]]['name']=$stocks ["name"];
|
||||
}
|
||||
if($_GET['date_from']==''){
|
||||
$_GET['date_from']=date('01.m.Y');
|
||||
} else {
|
||||
$date_from=date('Y-m-d 00:00:01',strtotime($_GET['date_from']));
|
||||
}
|
||||
if($_GET['date_to']==''){
|
||||
$_GET['date_to']=date('t.m.Y');
|
||||
} else {
|
||||
$date_to=date('Y-m-d 23:59:59',strtotime($_GET['date_to']));
|
||||
}
|
||||
$show_result=false;
|
||||
if(isset($_REQUEST['submit']) && $_REQUEST['submit']!=''){
|
||||
|
||||
$show_result=true;
|
||||
|
||||
$p = new EcmProduct();
|
||||
|
||||
$p->retrieve($_GET['product_id']);
|
||||
$product_indeks=$p->code;
|
||||
$lists = return_app_list_strings_language('pl_pl');
|
||||
$product_unit= $lists['ecmproducts_unit_dom'][$p->unit_id];
|
||||
|
||||
$startData=getStartValues($_GET ["product_id"],$_GET ["selectStock"],$date_from);
|
||||
|
||||
$start_quantity=$startData[0];
|
||||
$start_value=$startData[1];
|
||||
|
||||
$data=getOperations($_GET ["product_id"],$_GET ["selectStock"],$date_from,$date_to,$start_quantity,$start_value);
|
||||
$records=$data[0];
|
||||
$sumTable=$data[1];
|
||||
}
|
||||
// create & execute smarty
|
||||
$smarty = new Sugar_Smarty ();
|
||||
global $mod_strings;
|
||||
$smarty->assign ( "MOD", $mod_strings );
|
||||
$smarty->assign ( "DATA", $records );
|
||||
$smarty->assign ( "sumTable", $sumTable );
|
||||
$smarty->assign ( "SHOW_RESULT", $show_result );
|
||||
$smarty->assign ( "date_from", $_GET['date_from'] );
|
||||
$smarty->assign ( "date_to", $_GET['date_to'] );
|
||||
$smarty->assign ( "TOTAL_VALUE_OLD", $total_value_old );
|
||||
$smarty->assign ( "TOTAL_QUANTITY_OLD", $total_quantity_old );
|
||||
$smarty->assign ( "TOTAL_VALUE_NOW", $total_value_now );
|
||||
$smarty->assign ( "TOTAL_QUANTITY_NOW", $total_quantity_now );
|
||||
$smarty->assign ( "rozchod_w", $rozchod_w );
|
||||
$smarty->assign ( "rozchod_q", $rozchod_q );
|
||||
$smarty->assign ( "przychod_w", $przychod_w );
|
||||
$smarty->assign ( "przychod_q", $przychod_q );
|
||||
$smarty->assign ("CONSIGNMENTS",$EcmConfig['consignments']);
|
||||
$smarty->assign ( "STOCKS", $datastocks );
|
||||
$smarty->assign ( "selectStock", $_GET ["selectStock"]);
|
||||
$smarty->assign ( "selectProductActive", $_GET ["selectProductActive"] );
|
||||
$smarty->assign ( "selectProductEol", $_GET ["selectProductEol"] );
|
||||
$smarty->assign ( "selectShowEmpty", $_GET ["selectShowEmpty"] );
|
||||
$smarty->assign ( "product_id", $_GET ["product_id"] );
|
||||
$smarty->assign ( "product_name", $_GET ["product_name"] );
|
||||
$smarty->assign ( "product_indeks", $product_indeks);
|
||||
$smarty->assign ( "product_unit", $product_unit );
|
||||
$smarty->assign ( "start_quantity", $start_quantity );
|
||||
$smarty->assign ( "start_value", $start_value );
|
||||
|
||||
// Eksport do PDF
|
||||
if( $_GET['toPDF'] == '1' ) {
|
||||
$output = $smarty->fetch( 'modules/EcmReports/tpls/PDF/ProductOptionHistory.tpl' );
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
unset($smarty);
|
||||
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 25, 10, 5, 5 );
|
||||
$p->setFooter('Strona {PAGENO} z {nbpg}');
|
||||
$comp = new EcmSysInfo();
|
||||
$p->SetHTMLHeader('<p style="text-align:left;font-size: 10px;">'.$comp->name.'<br>
|
||||
Raport operacji magazynowych<br>Data wydruku: '.date("d.m.Y").'<br>Stan magazynowy za okres: '.$_GET['date_from'].' - '.$_GET['date_to'].'<br>Magazyn: '.$s[$_GET ["selectStock"]]['name']. '<br>Strona {PAGENO} z {nbpg}</p>');
|
||||
//$p->setTitle($mod_strings["LBL_REPORT_STOCKS_DOCS"]);
|
||||
//echo $output;
|
||||
$p->writeHTML( $output );
|
||||
|
||||
$p->Output ();
|
||||
} else {
|
||||
$smarty->display ( 'modules/EcmReports/tpls/ProductOperationHistory.tpl' );
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
function aasort (&$array, $key) {
|
||||
$sorter=array();
|
||||
$ret=array();
|
||||
reset($array);
|
||||
foreach ($array as $ii => $va) {
|
||||
$sorter[$ii]=$va[$key];
|
||||
}
|
||||
asort($sorter);
|
||||
foreach ($sorter as $ii => $va) {
|
||||
$ret[$ii]=$array[$ii];
|
||||
}
|
||||
$array=$ret;
|
||||
}
|
||||
|
||||
$db=$GLOBALS['db'];
|
||||
$ss = new Sugar_Smarty ();
|
||||
|
||||
$lists=array();
|
||||
$users=array();
|
||||
$OrderByDateList=array();
|
||||
|
||||
$moduleLabels['accounts']='Kontrahenci';
|
||||
$moduleLabels['ecmproducts']='Produkty';
|
||||
$moduleLabels['ecmquotes']='Oferty';
|
||||
$moduleLabels['ecmsales']='Zamówienia sprzedaży';
|
||||
$moduleLabels['ecminvoiceouts']='Faktury';
|
||||
$moduleLabels['ecmprepaymentinvoices']='Faktury zaliczkowe';
|
||||
$moduleLabels['ecmreceipts']='Paragony';
|
||||
$moduleLabels['notes']='Notatki';
|
||||
$moduleLabels['tasks']='Zadania';
|
||||
$moduleLabels['documents']='Dokumenty';
|
||||
|
||||
if($_REQUEST['date_from']=== null)$_REQUEST['date_from']=date('01.m.Y');
|
||||
if($_REQUEST['date_to']===null)$_REQUEST['date_to']=date('t.m.Y');
|
||||
|
||||
$date_from =$_REQUEST['date_from'];
|
||||
$date_to=$_REQUEST['date_to'];
|
||||
|
||||
$querys['accounts']="select id,created_by,date_entered,date_modified,name from accounts where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['ecmproducts']="select id,created_by,date_entered,date_modified,name from ecmproducts where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['ecmquotes']="select id,created_by,date_entered,date_modified,name from ecmquotes where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['ecmsales']="select id,created_by,date_entered,date_modified,name from ecmsales where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['ecminvoiceouts']="select id,created_by,date_entered,date_modified,name from ecminvoiceouts where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['ecmprepaymentinvoices']="select id,created_by,date_entered,date_modified,name from ecmprepaymentinvoices where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['ecmreceipts']="select id,created_by,date_entered,date_modified,name from ecmreceipts where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['notes']="select id,created_by,date_entered,date_modified,name from notes where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['tasks']="select id,created_by,date_entered,date_modified,name from tasks where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$querys['documents']="select id,created_by,date_entered,date_modified,document_number as name from documents where date_entered >='".date('Y-m-d',strtotime($date_from))."' and date_entered <='".date('Y-m-d',strtotime($date_to))."'";
|
||||
|
||||
$user_query='select id,first_name,last_name from users where deleted=0';
|
||||
|
||||
$ss->assign("date_to", $date_to);
|
||||
$ss->assign("date_from", $date_from);
|
||||
|
||||
if($_REQUEST['process']){
|
||||
|
||||
$zap=$db->query($user_query);
|
||||
while($dane=$db->fetchByAssoc($zap)){
|
||||
if($dane['id']==1)continue;
|
||||
$dane['nr']=1;
|
||||
$users[$dane['id']]=$dane;
|
||||
$lists[$dane['id']]=null;
|
||||
foreach ($querys as $key => $val){
|
||||
$lists[$dane['id']][$key] =null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($querys as $key => $val){
|
||||
$nr=1;
|
||||
$res=$db->query($val);
|
||||
while($dane=$db->fetchByAssoc($res)){
|
||||
if($dane['created_by']==1)continue;
|
||||
$dane['sort']=date('YmdHis',strtotime($dane['date_entered']));
|
||||
$lists[$dane['created_by']][$key][]=$dane;
|
||||
$dane['module']=$key;
|
||||
$dane['nr']=$users[$dane['created_by']]['nr'];
|
||||
$OrderByDateList[$dane['created_by']][]=$dane;
|
||||
$users[$dane['created_by']]['nr']++;
|
||||
}
|
||||
}
|
||||
|
||||
$zap=$db->query($user_query);
|
||||
while($dane=$db->fetchByAssoc($zap)){
|
||||
if(count($OrderByDateList[$dane['id']])>0){
|
||||
|
||||
|
||||
aasort($OrderByDateList[$dane['id']],"sort");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$ss->assign("lists", $lists);
|
||||
$ss->assign("OrderByDateList", $OrderByDateList);
|
||||
$ss->assign("users", $users);
|
||||
$ss->assign("moduleLabels", $moduleLabels);
|
||||
$ss->assign("colWidth", round(90/count($moduleLabels),2));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$content = $ss->fetch ( 'modules/EcmReports/tpls/RaportAktywnosci.tpl' );
|
||||
echo $content;
|
||||
?>
|
||||
@@ -0,0 +1,149 @@
|
||||
<?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' );
|
||||
?>
|
||||
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
global $mod_strings, $app_list_strings, $db;
|
||||
// kontrahent
|
||||
if(!$_REQUEST['date_from'])
|
||||
$date_from = date("01.m.Y");
|
||||
else
|
||||
$date_from = $_REQUEST["date_from"];
|
||||
|
||||
if(!$_REQUEST['date_to'])
|
||||
$date_to = date("d.m.Y");
|
||||
else
|
||||
$date_to = $_REQUEST["date_to"];
|
||||
|
||||
if(!class_exists('EcmInvoiceOut')){
|
||||
include_once('modules/EcmInvoiceouts/EcmInvoiceout.php');
|
||||
};
|
||||
if(!class_exists('EcmReceipts')){
|
||||
include_once('modules/EcmReceipts/EcmReceipt.php');
|
||||
};
|
||||
|
||||
//get trader list
|
||||
$query_trader = "select ecminvoiceouts.assigned_user_id AS user_id , concat(users.first_name, ' ', users.last_name) AS user_name FROM ecminvoiceouts, users WHERE ecminvoiceouts.deleted = 0 and ecminvoiceouts.canceled = 0 AND users.id = ecminvoiceouts.assigned_user_id group by user_id ORDER BY user_name";
|
||||
$trader_result = $db->query($query_trader);
|
||||
$trader_array = array(""=>"");
|
||||
while($row = $db->fetchByAssoc($trader_result)){
|
||||
$trader_array[$row['user_id']] = $row['user_name'];
|
||||
}
|
||||
|
||||
//Get Stock List
|
||||
|
||||
$query_stock = "Select id, name from ecmstocks where deleted=0";
|
||||
$stock_result = $db->query($query_stock);
|
||||
$stock_array = array(""=>"");
|
||||
while($row = $db->fetchByAssoc($stock_result)){
|
||||
$stock_array[$row['id']] = $row['name'];
|
||||
}
|
||||
|
||||
//Szykowanie zapytań
|
||||
//Zakres dat
|
||||
$whereInvoice['ecminvoiceouts'][] = 'register_date>="' . getFormatedDateForDB($date_from) . '"';
|
||||
$whereInvoice['ecminvoiceouts'][] = 'register_date<="' . getFormatedDateForDB($date_to) . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'register_date>="' . getFormatedDateForDB($date_from) . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'register_date<="' . getFormatedDateForDB($date_to) . '"';
|
||||
//Handlowiec
|
||||
if($_REQUEST['trader'] != ""){
|
||||
$whereInvoice['ecminvoiceouts'][] = 'assigned_user_id="' . $_REQUEST['trader'] . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'assigned_user_id="' . $_REQUEST['trader'] . '"';
|
||||
}
|
||||
|
||||
//Magazyn
|
||||
$stocks = $_REQUEST['stocks'];
|
||||
if(count($stocks)>0){
|
||||
if(in_array("",$stocks)){
|
||||
$indeks = array_search("",$stocks);
|
||||
unset($stocks[$indeks]);
|
||||
}
|
||||
if(count($stocks)>0){
|
||||
$stocksList = array();
|
||||
$value = array_values ( $stocks );
|
||||
$whereInvoice['ecminvoiceouts'][] = 'stock_id IN ("' . implode('","',$value) . '")';
|
||||
$whereRecipe['ecmrecipes'][] = 'stock_id IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
//Grupa
|
||||
$product_group = $_REQUEST['product_group'];
|
||||
if(count($product_group)>0){
|
||||
if(in_array("",$product_group)){
|
||||
$indeks = array_search("",$product_group);
|
||||
unset($product_group[$indeks]);
|
||||
}
|
||||
if(count($product_group)>0){
|
||||
$product_group_list = array();
|
||||
$value = array_values ( $product_group );
|
||||
$whereInvoice['ecmproducts'][] = 'ks_group IN ("' . implode('","',$value) . '")';
|
||||
$whereRecipe['ecmproducts'][] = 'ks_group IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
//Typ dokumentu
|
||||
$document_sales_type = $_REQUEST['document_sales_type'];
|
||||
if(count($document_sales_type)>0){
|
||||
if(in_array("",$document_sales_type)){
|
||||
$indeks = array_search("",$document_sales_type);
|
||||
unset($document_sales_type[$indeks]);
|
||||
}
|
||||
|
||||
if(count($document_sales_type)>0){
|
||||
$tmpInvoiceType = array();
|
||||
$tmpRecipeType = array();
|
||||
$receiptDo = false;
|
||||
$invoceDo = true;
|
||||
foreach($document_sales_type as $key => $value){
|
||||
switch($value){
|
||||
case 'invoice':
|
||||
$tmpInvoiceType[] = 'normal';
|
||||
$invoceDo = true;
|
||||
break;
|
||||
case 'invoice_correct':
|
||||
$invoceDo = true;
|
||||
$tmpInvoiceType[] = 'correct';
|
||||
break;
|
||||
case 'recipe':
|
||||
$receiptDo = true;
|
||||
$tmpRecipeType[] = 'normal';
|
||||
break;
|
||||
case 'recipe_correct':
|
||||
$receiptDo = true;
|
||||
$tmpRecipeType[] = 'correct';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(count($tmpInvoiceType)>0){
|
||||
$value = array_values ( $tmpInvoiceType );
|
||||
$whereInvoice['ecminvoiceouts'][] = 'type IN ("' . implode('","',$value) . '")';
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
}
|
||||
|
||||
if(count($tmpRecipeType)>0){
|
||||
$value = array_values ( $tmpRecipeType );
|
||||
$whereRecipe['ecmrecipes'][] = 'type IN ("' . implode('","',$value) . '")';
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
|
||||
}else{
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
}else{
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
|
||||
// Przetwarzanie danych
|
||||
$data = array();
|
||||
foreach($dataInvoice as $indeks => $invoice){
|
||||
$data[$invoice['parent_id']]['name'] = '<a target="_blank" href="index.php?module=Accounts&return_module=Account&action=DetailView&parentTab=Kontakty&record=' . $invoice['parent_id'] . '">' . $invoice['parent_name'] . '</a>';
|
||||
$data[$invoice['parent_id']]['total_netto'] += $invoice['total_netto'];
|
||||
$data[$invoice['parent_id']]['price_purchase'] += $invoice['purchase_price'];
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$data[$invoice['parent_id']]['name']= $invoice['parent_name'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach($dataRecipe as $indeks => $invoice){
|
||||
$data[$invoice['parent_id']]['name'] = '<a target="_blank" href="index.php?module=Accounts&return_module=Account&action=DetailView&parentTab=Kontakty&record=' . $invoice['parent_id'] . '">' . $invoice['parent_name'] . '</a>';
|
||||
$data[$invoice['parent_id']]['total_netto'] += $invoice['total_netto'];
|
||||
$data[$invoice['parent_id']]['price_purchase'] += $invoice['purchase_price'];
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$data[$invoice['parent_id']]['name']= $invoice['parent_name'];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Szykowanie wyświetlania
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("APP_LIST_STRINGS", $app_list_strings);
|
||||
$smarty->assign("DATA", $data);
|
||||
$smarty->assign("TRADERS_LIST", $trader_array);
|
||||
$smarty->assign("STOCK_LIST", $stock_array);
|
||||
|
||||
|
||||
//Ustawiamy przeslane dane
|
||||
//$date_from = $GLOBALS['timedate']->to_display_date($date_from);
|
||||
//$date_to = $GLOBALS['timedate']->to_display_date($date_to);
|
||||
$smarty->assign("date_from_value", $date_from );
|
||||
$smarty->assign("date_to_value", $date_to );
|
||||
$smarty->assign("TRADER_SELECTED", $_REQUEST['trader']);
|
||||
$smarty->assign("account_invoice_type_dom", $app_list_strings['account_invoice_type_dom']);
|
||||
|
||||
if($_REQUEST['to_pdf']!='1'){
|
||||
$smarty->assign("STOCK_SELECTED", $_REQUEST['stocks']);
|
||||
$smarty->assign("PRODUCT_GROUP_SELECTED", $_REQUEST['product_group']);
|
||||
$smarty->assign("DOCUMENT_SALES_SELECTED", $_REQUEST['document_sales_type']);
|
||||
echo $smarty->display('modules/EcmReports/tpls/ReportSalesByContractor.tpl');
|
||||
}else{
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$header=array();
|
||||
$header[]='nazwa';
|
||||
$header[]='sprzedaż netto';
|
||||
$header[]='koszt zakupu';
|
||||
$header[]='dochód';
|
||||
$filename='modules/Home/Files/raport_sprzedazy_wg_nabywcow_'.date('d_m-Y').'.csv';
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
foreach ($data as $key=>$val){
|
||||
$line=array();
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['name'])));
|
||||
$line[]=str_replace(".",",",$val['total_netto']);
|
||||
$line[]=str_replace(".",",",$val['price_purchase']);
|
||||
$line[]=str_replace(".",",",$val['total_netto']-$val['price_purchase']);
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
print $filename;
|
||||
} else {
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
$smarty->assign("STOCK_SELECTED", $_REQUEST['stocks']);
|
||||
$smarty->assign("PRODUCT_GROUP_SELECTED", $_REQUEST['product_group']);
|
||||
$smarty->assign("DOCUMENT_SALES_SELECTED", $_REQUEST['document_sales_type']);
|
||||
$EcmSysInfos = new EcmSysInfo();
|
||||
|
||||
$content = $smarty->fetch('modules/EcmReports/tpls/ReportSalesByContractorPDF.tpl');
|
||||
$mPDF = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 10, 10, 5, 5 );
|
||||
$mPDF->mirrorMargins = 1;
|
||||
$mPDF->WriteHTML($content);
|
||||
|
||||
$dir = 'upload/' . $EcmSysInfos->getDatabaseName() . '/pdf/EcmReports/';
|
||||
if(!is_dir($dir)){
|
||||
mkdir($dir, '755', true);
|
||||
}
|
||||
$file_name = $dir . str_replace(".","",$date_from) . "_" . str_replace(".","",$date_to) ."_Raport_Sprzedazy_Podzial_Kontrahenci.pdf";
|
||||
$mPDF->Output( $file_name, "F");
|
||||
print $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
function getFormatedDateForDB($data){
|
||||
if(strpos($data,".")>0){
|
||||
$split = explode (".",$data);
|
||||
$return_data = $split[2] . "-" . $split[1] . "-" .$split['0'];
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
global $mod_strings, $app_list_strings, $db;
|
||||
// kontrahent
|
||||
if(!$_REQUEST['date_from'])
|
||||
$date_from = date("01.m.Y");
|
||||
else
|
||||
$date_from = $_REQUEST["date_from"];
|
||||
|
||||
if(!$_REQUEST['date_to'])
|
||||
$date_to = date("d.m.Y");
|
||||
else
|
||||
$date_to = $_REQUEST["date_to"];
|
||||
|
||||
if(!class_exists('EcmInvoiceOut')){
|
||||
include_once('modules/EcmInvoiceouts/EcmInvoiceout.php');
|
||||
};
|
||||
if(!class_exists('EcmReceipts')){
|
||||
include_once('modules/EcmReceipts/EcmReceipt.php');
|
||||
};
|
||||
|
||||
//get trader list
|
||||
$query_trader = "select ecminvoiceouts.assigned_user_id AS user_id , concat(users.first_name, ' ', users.last_name) AS user_name FROM ecminvoiceouts, users WHERE ecminvoiceouts.deleted = 0 and ecminvoiceouts.canceled = 0 AND users.id = ecminvoiceouts.assigned_user_id group by user_id ORDER BY user_name";
|
||||
$trader_result = $db->query($query_trader);
|
||||
$trader_array = array(""=>"");
|
||||
while($row = $db->fetchByAssoc($trader_result)){
|
||||
$trader_array[$row['user_id']] = $row['user_name'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Get Stock List
|
||||
$query_stock = "Select id, name from ecmstocks where deleted=0";
|
||||
$stock_result = $db->query($query_stock);
|
||||
$stock_array = array(""=>"");
|
||||
while($row = $db->fetchByAssoc($stock_result)){
|
||||
$stock_array[$row['id']] = $row['name'];
|
||||
}
|
||||
|
||||
//Szykowanie zapytań
|
||||
//Zakres dat
|
||||
$whereInvoice['ecminvoiceouts'][] = 'register_date>="' . getFormatedDateForDB($date_from) . '"';
|
||||
$whereInvoice['ecminvoiceouts'][] = 'register_date<="' . getFormatedDateForDB($date_to) . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'register_date>="' . getFormatedDateForDB($date_from) . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'register_date<="' . getFormatedDateForDB($date_to) . '"';
|
||||
//Handlowiec
|
||||
if($_REQUEST['trader'] != ""){
|
||||
$whereInvoice['ecminvoiceouts'][] = 'assigned_user_id="' . $_REQUEST['trader'] . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'assigned_user_id="' . $_REQUEST['trader'] . '"';
|
||||
}
|
||||
//Kontrahent
|
||||
if($_REQUEST['account_id'] != ""){
|
||||
$whereInvoice['ecminvoiceouts'][] = 'parent_id="' . $_REQUEST['account_id'] . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'parent_id="' . $_REQUEST['account_id'] . '"';
|
||||
}
|
||||
//Magazyn
|
||||
$stocks = $_REQUEST['stocks'];
|
||||
if(count($stocks)>0){
|
||||
if(in_array("",$stocks)){
|
||||
$indeks = array_search("",$stocks);
|
||||
unset($stocks[$indeks]);
|
||||
}
|
||||
if(count($stocks)>0){
|
||||
$stocksList = array();
|
||||
$value = array_values ( $stocks );
|
||||
$whereInvoice['ecminvoiceouts'][] = 'stock_id IN ("' . implode('","',$value) . '")';
|
||||
$whereRecipe['ecmrecipes'][] = 'stock_id IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
//Grupa
|
||||
$product_group = $_REQUEST['product_group'];
|
||||
if(count($product_group)>0){
|
||||
if(in_array("",$product_group)){
|
||||
$indeks = array_search("",$product_group);
|
||||
unset($product_group[$indeks]);
|
||||
}
|
||||
if(count($product_group)>0){
|
||||
$product_group_list = array();
|
||||
$value = array_values ( $product_group );
|
||||
$whereInvoice['ecmproducts'][] = 'ks_group IN ("' . implode('","',$value) . '")';
|
||||
$whereRecipe['ecmproducts'][] = 'ks_group IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
// Typ PDF
|
||||
$pdf_type = $_REQUEST['pdf_type'];
|
||||
if(count($pdf_type)>0){
|
||||
if(in_array("",$pdf_type)){
|
||||
$indeks = array_search("",$pdf_type);
|
||||
unset($pdf_type[$indeks]);
|
||||
}
|
||||
if(count($pdf_type)>0){
|
||||
$product_group_list = array();
|
||||
$value = array_values ( $pdf_type );
|
||||
$whereInvoice['ecmproducts'][] = 'pdf_type IN ("' . implode('","',$value) . '")';
|
||||
// $whereRecipe['ecmproducts'][] = 'pdf_type IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
//Typ dokumentu
|
||||
$document_sales_type = $_REQUEST['document_sales_type'];
|
||||
if(count($document_sales_type)>0){
|
||||
if(in_array("",$document_sales_type)){
|
||||
$indeks = array_search("",$document_sales_type);
|
||||
unset($document_sales_type[$indeks]);
|
||||
}
|
||||
|
||||
if(count($document_sales_type)>0){
|
||||
$tmpInvoiceType = array();
|
||||
$tmpRecipeType = array();
|
||||
$receiptDo = false;
|
||||
$invoceDo = true;
|
||||
foreach($document_sales_type as $key => $value){
|
||||
switch($value){
|
||||
case 'invoice':
|
||||
$tmpInvoiceType[] = 'normal';
|
||||
$invoceDo = true;
|
||||
break;
|
||||
case 'invoice_correct':
|
||||
$invoceDo = true;
|
||||
$tmpInvoiceType[] = 'correct';
|
||||
break;
|
||||
case 'recipe':
|
||||
$receiptDo = true;
|
||||
$tmpRecipeType[] = 'normal';
|
||||
break;
|
||||
case 'recipe_correct':
|
||||
$receiptDo = true;
|
||||
$tmpRecipeType[] = 'correct';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(count($tmpInvoiceType)>0){
|
||||
$value = array_values ( $tmpInvoiceType );
|
||||
$whereInvoice['ecminvoiceouts'][] = 'type IN ("' . implode('","',$value) . '")';
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
}
|
||||
|
||||
if(count($tmpRecipeType)>0){
|
||||
$value = array_values ( $tmpRecipeType );
|
||||
$whereRecipe['ecmrecipes'][] = 'type IN ("' . implode('","',$value) . '")';
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
|
||||
}else{
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
}else{
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
|
||||
// Przetwarzanie danych
|
||||
$data = array();
|
||||
foreach($dataInvoice as $indeks => $invoice){
|
||||
if($invoice['document_type'] == 'EcmInvoiceOuts'){
|
||||
$docname = 'Faktura';
|
||||
}elseif($invoice['document_type'] == 'EcmReceipts'){
|
||||
$docname .= 'Paragon';
|
||||
}
|
||||
if($invoice['type'] == 'correct'){
|
||||
$docname .= ' Korekta';
|
||||
}
|
||||
$docname .= " " . $invoice['document_no'];
|
||||
$data[$invoice['id']]['name'] = '<a target="_blank" href="index.php?module=' . $invoice['document_type'] . '&action=DetailView&parentTab=Sprzedaż&record=' . $invoice['parent_id'] . '">' . $docname . '</a>';
|
||||
$data[$invoice['id']]['register_date'] = getFormatedDateForView($invoice['register_date']);
|
||||
$data[$invoice['id']]['total_netto'] += $invoice['total_netto'];
|
||||
$data[$invoice['id']]['total_brutto'] += $invoice['total_brutto'];
|
||||
$data[$invoice['id']]['price_purchase'] += $invoice['purchase_price'];
|
||||
$data[$invoice['id']]['parent_name'] = '<a target="_blank" href="index.php?module=Accounts&return_module=Account&action=DetailView&parentTab=Kontakty&record=' . $invoice['parent_id'] . '">' . $invoice['parent_name'] . '</a>';
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$data[$invoice['id']]['parent_name']= $invoice['parent_name'];
|
||||
$data[$invoice['id']]['name'] =$docname;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($dataRecipe as $indeks => $invoice){
|
||||
if($invoice['document_type'] == 'EcmInvoiceOuts'){
|
||||
$docname = 'Faktura';
|
||||
}elseif($invoice['document_type'] == 'EcmReceipts'){
|
||||
$docname = 'Paragon';
|
||||
}
|
||||
if($invoice['type'] == 'correct'){
|
||||
$docname .= ' Korekta';
|
||||
}
|
||||
$docname .= " " . $invoice['document_no'];
|
||||
$data[$invoice['id']]['name'] = '<a target="_blank" href="index.php?module=' . $invoice['document_type']. '&action=DetailView&parentTab=Sprzedaż&record=' . $invoice['parent_id'] . '">' . $docname . '</a>';
|
||||
$data[$invoice['id']]['register_date'] = getFormatedDateForView($invoice['register_date']);
|
||||
$data[$invoice['id']]['total_netto'] += $invoice['total_netto'];
|
||||
$data[$invoice['id']]['total_brutto'] += $invoice['total_brutto'];
|
||||
$data[$invoice['id']]['price_purchase'] += $invoice['purchase_price'];
|
||||
$data[$invoice['id']]['parent_name'] = '<a target="_blank" href="index.php?module=Accounts&return_module=Account&action=DetailView&parentTab=Kontakty&record=' . $invoice['parent_id'] . '">' . $invoice['parent_name'] . '</a>';
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$data[$invoice['id']]['parent_name']= $invoice['parent_name'];
|
||||
$data[$invoice['id']]['name'] =$docname;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//Szykowanie wyświetlania
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("APP_LIST_STRINGS", $app_list_strings);
|
||||
$smarty->assign("DATA", $data);
|
||||
$smarty->assign("TRADERS_LIST", $trader_array);
|
||||
$smarty->assign("STOCK_LIST", $stock_array);
|
||||
|
||||
|
||||
//Ustawiamy przeslane dane
|
||||
//$date_from = $GLOBALS['timedate']->to_display_date($date_from);
|
||||
//$date_to = $GLOBALS['timedate']->to_display_date($date_to);
|
||||
$smarty->assign("date_from_value", $date_from );
|
||||
$smarty->assign("date_to_value", $date_to );
|
||||
$smarty->assign("TRADER_SELECTED", $_REQUEST['trader']);
|
||||
$smarty->assign("account_invoice_type_dom", $app_list_strings['account_invoice_type_dom']);
|
||||
$smarty->assign("STOCK_SELECTED", $_REQUEST['stocks']);
|
||||
$smarty->assign("PRODUCT_GROUP_SELECTED", $_REQUEST['product_group']);
|
||||
$smarty->assign("DOCUMENT_SALES_SELECTED", $_REQUEST['document_sales_type']);
|
||||
$smarty->assign("PDF_TYPE_SELECTED", $_REQUEST['pdf_type']);
|
||||
$smarty->assign("ACCOUNT_ID", $_REQUEST['account_id']);
|
||||
$smarty->assign("ACCOUNT_NAME", $_REQUEST['account_name']);
|
||||
|
||||
if($_REQUEST['to_pdf']!='1'){
|
||||
echo $smarty->display('modules/EcmReports/tpls/ReportSalesByDocument.tpl');
|
||||
}else{
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$header=array();
|
||||
$header[]='dokument';
|
||||
$header[]='data dokumentu';
|
||||
$header[]='kontrahent';
|
||||
$header[]='sprzedaż netto';
|
||||
$header[]='sprzedaż brutto';
|
||||
$header[]='koszt zakupu';
|
||||
$header[]='dochód';
|
||||
$filename='modules/Home/Files/raport_sprzedazy_wartosciowy_'.date('d_m-Y').'.csv';
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
foreach ($data as $key=>$val){
|
||||
$line=array();
|
||||
$line[]=$val['name'];
|
||||
$line[]=$val['register_date'];
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['parent_name'])));
|
||||
$line[]=str_replace(".",",",$val['total_netto']);
|
||||
$line[]=str_replace(".",",",$val['total_brutto']);
|
||||
$line[]=str_replace(".",",",$val['price_purchase']);
|
||||
$line[]=str_replace(".",",",$val['total_netto']-$val['price_purchase']);
|
||||
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
print $filename;
|
||||
} else {
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
$EcmSysInfos = new EcmSysInfo();
|
||||
|
||||
$content = $smarty->fetch('modules/EcmReports/tpls/ReportSalesByDocumentPDF.tpl');
|
||||
$mPDF = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 10, 10, 5, 5 );
|
||||
$mPDF->mirrorMargins = 1;
|
||||
$mPDF->WriteHTML($content);
|
||||
|
||||
$dir = 'upload/' . $EcmSysInfos->getDatabaseName() . '/pdf/EcmReports/';
|
||||
if(!is_dir($dir)){
|
||||
mkdir($dir, '755', true);
|
||||
}
|
||||
$file_name = $dir . str_replace(".","",$date_from) . "_" . str_replace(".","",$date_to) ."_Raport_Sprzedazy_Raport_wartosciowy.pdf";
|
||||
$mPDF->Output( $file_name, "F");
|
||||
print $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
function getFormatedDateForDB($data){
|
||||
if(strpos($data,".")>0){
|
||||
$split = explode (".",$data);
|
||||
$return_data = $split[2] . "-" . $split[1] . "-" .$split['0'];
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
function getFormatedDateForView($data){
|
||||
if(strpos($data,"-")>0){
|
||||
$split = explode ("-",$data);
|
||||
$return_data = $split[2] . "." . $split[1] . "." .$split['0'];
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
|
||||
ini_set('memory_limit', '1000000000M');
|
||||
|
||||
// ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
// ini_set('display_startup_errors', 1);
|
||||
|
||||
global $mod_strings, $app_list_strings, $db;
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
// Array with months
|
||||
$array_months = [
|
||||
1 => 'Styczeń',
|
||||
2 => 'Luty',
|
||||
3 => 'Marzec',
|
||||
4 => 'Kwiecień',
|
||||
5 => 'Maj',
|
||||
6 => 'Czerwiec',
|
||||
7 => 'Lipec',
|
||||
8 => 'Sierpień',
|
||||
9 => 'Wrzesień',
|
||||
10 => 'Październik',
|
||||
11 => 'Listopad',
|
||||
12 => 'Grudzizeń'
|
||||
];
|
||||
|
||||
$relationsQuery = " FROM `ecminvoiceouts`
|
||||
INNER JOIN `accounts` ON
|
||||
(accounts.id = ecminvoiceouts.parent_id)
|
||||
|
||||
INNER JOIN `ecminvoiceoutitems` ON
|
||||
(ecminvoiceoutitems.ecminvoiceout_id = ecminvoiceouts.id)
|
||||
|
||||
INNER JOIN `ecmproducts` ON
|
||||
(ecmproducts.id = ecminvoiceoutitems.ecmproduct_id) ";
|
||||
|
||||
// Filters for query
|
||||
$whereFilter = "";
|
||||
|
||||
// Years and months
|
||||
$years_group = isset($_REQUEST['years_group']) ? $_REQUEST['years_group'] : [0];
|
||||
$months_group = isset($_REQUEST['months_group']) ? $_REQUEST['months_group'] : [0];
|
||||
|
||||
if((count($years_group) > 0) AND (count($months_group) > 0)){
|
||||
$_months_group = strlen($months_group[0]) == 1 ? '0'.$months_group[0] : $months_group[0];
|
||||
$value = $years_group[0] . '-' . $_months_group;
|
||||
$whereFilter .= ' AND ecminvoiceouts.register_date >= "' . $value . '" ';
|
||||
}
|
||||
|
||||
// Types
|
||||
$types_group = isset($_REQUEST['types_group']) ? $_REQUEST['types_group'] : [0];
|
||||
if(count($types_group) > 0){
|
||||
if(in_array("",$types_group)){
|
||||
$index = array_search("",$types_group);
|
||||
unset($types_group[$index]);
|
||||
}
|
||||
if(count($types_group) > 0){
|
||||
$value = array_values ( $types_group );
|
||||
$whereFilter .= ' AND accounts.account_type IN ("' . implode('","',$value) . '") ';
|
||||
}
|
||||
}
|
||||
|
||||
// Group_ks
|
||||
$product_group = isset($_REQUEST['product_group']) ? $_REQUEST['product_group'] : [0];
|
||||
if(count($product_group) > 0){
|
||||
if(in_array("",$product_group)){
|
||||
$index = array_search("",$product_group);
|
||||
unset($product_group[$index]);
|
||||
}
|
||||
if(count($product_group) > 0){
|
||||
$value = array_values ( $product_group );
|
||||
$whereFilter .= ' AND ecmproducts.ks_group IN ("' . implode('","',$value) . '") ';
|
||||
}
|
||||
}
|
||||
|
||||
// Get all groups from ecmproducts table
|
||||
$group_ks_result = $db->query("SELECT DISTINCT `ks_group` " . $relationsQuery . " " . $whereFilter . " ORDER BY `ks_group`");
|
||||
while($row = $db->fetchByAssoc($group_ks_result)) { $group_ks[$row['ks_group']] = $app_list_strings['ecmproducts_group_ks_dom'][ $row['ks_group'] ]; }
|
||||
|
||||
// Get all types from accounts table
|
||||
$types_result = $db->query("SELECT DISTINCT accounts.account_type " . $relationsQuery . " ORDER BY `account_type`");
|
||||
while($row = $db->fetchByAssoc($types_result)) { $types[$row['account_type']] = $app_list_strings['account_type_dom'][ $row['account_type'] ]; }
|
||||
|
||||
// Get years from ecminvoiceouts table
|
||||
$years_result = $db->query("SELECT DISTINCT YEAR(register_date) AS `years` " . $relationsQuery . " ORDER BY `years`");
|
||||
while($row = $db->fetchByAssoc($years_result)) { $years[] = $row['years']; }
|
||||
|
||||
// Get months from ecminvoiceouts table
|
||||
$months_result = $db->query("SELECT DISTINCT MONTH(register_date) AS `months` " . $relationsQuery . " ORDER BY `months`");
|
||||
while($row = $db->fetchByAssoc($months_result)) { $months[$row['months']] = $row['months']; }
|
||||
|
||||
// Generate table data
|
||||
$table_request = "
|
||||
SELECT
|
||||
|
||||
COUNT(DISTINCT accounts.id) AS `accounts_count`,
|
||||
COUNT(ecminvoiceouts.id) AS `ecminvoiceouts_count`,
|
||||
|
||||
|
||||
accounts.account_type AS `accounts_type`,
|
||||
|
||||
ecmproducts.ks_group AS `ecmproducts_group_ks`,
|
||||
|
||||
SUM(ROUND(
|
||||
|
||||
CASE
|
||||
|
||||
WHEN ecminvoiceouts.type = 'normal' THEN
|
||||
ecminvoiceoutitems.total_netto *
|
||||
|
||||
CASE WHEN ecminvoiceouts.currency_value_nbp != '' THEN
|
||||
ecminvoiceouts.currency_value_nbp
|
||||
ELSE 1
|
||||
|
||||
END
|
||||
|
||||
ELSE
|
||||
ecminvoiceoutitems.total_netto_corrected *
|
||||
|
||||
CASE WHEN ecminvoiceouts.currency_value_nbp != '' THEN
|
||||
ecminvoiceouts.currency_value_nbp
|
||||
ELSE 1
|
||||
END
|
||||
|
||||
END
|
||||
|
||||
,2)) AS `ecminvoiceouts_total_brutto`,
|
||||
|
||||
MONTH(ecminvoiceouts.register_date) AS `ecminvoiceouts_month`,
|
||||
YEAR(ecminvoiceouts.register_date) AS `ecminvoiceouts_year`
|
||||
|
||||
" . $relationsQuery . "
|
||||
|
||||
" . $whereFilter . "
|
||||
|
||||
AND ecminvoiceouts.deleted=0
|
||||
AND ecminvoiceouts.canceled=0
|
||||
|
||||
GROUP BY `ecminvoiceouts_year`, `ecminvoiceouts_month`, `accounts_type`, `ks_group`
|
||||
ORDER BY `ecminvoiceouts_year`, `ecminvoiceouts_month`, `accounts_type`, `ecmproducts_group_ks`
|
||||
";
|
||||
$table_result = $db->query($table_request);
|
||||
while($row = $db->fetchByAssoc($table_result)) { $table_result_array[] = $row; }
|
||||
|
||||
// Genarate main array
|
||||
$generate_table_array = [];
|
||||
foreach ($table_result_array as $table_key => $table) {
|
||||
$generate_table_array
|
||||
[$table['ecminvoiceouts_year']]
|
||||
[$table['ecminvoiceouts_month']]
|
||||
[$table['accounts_type']]
|
||||
['accounts_count'] = $table['accounts_count'];
|
||||
|
||||
$generate_table_array
|
||||
[$table['ecminvoiceouts_year']]
|
||||
[$table['ecminvoiceouts_month']]
|
||||
[$table['accounts_type']]
|
||||
['documents_count'] = $table['ecminvoiceouts_count'];
|
||||
|
||||
$generate_table_array
|
||||
[$table['ecminvoiceouts_year']]
|
||||
[$table['ecminvoiceouts_month']]
|
||||
[$table['accounts_type']]
|
||||
['accounts_type']
|
||||
[$table['ecmproducts_group_ks']] = $table['ecminvoiceouts_total_brutto'];
|
||||
}
|
||||
|
||||
//echo "<pre>";
|
||||
//var_dump($table_result_array);
|
||||
//die;
|
||||
|
||||
function xsl($group_ks, $table_result_array, $array_months, $types, $generate_table_array) {
|
||||
$filename='modules/Home/Files/raport_sprzedazy_w_groupach_'.date('d_m-Y').'.csv';
|
||||
$fp = fopen($filename,'w');
|
||||
|
||||
$header = generate_header($group_ks);
|
||||
$line = generate_line($group_ks, $table_result_array, $array_months, $types, $generate_table_array);
|
||||
|
||||
fwrite($fp, implode(";", $header).PHP_EOL);
|
||||
|
||||
foreach ($line as $l) {
|
||||
$l = coding($l);
|
||||
fwrite($fp, implode(";", $l).PHP_EOL);
|
||||
}
|
||||
|
||||
print $filename;
|
||||
// echo "<pre>";
|
||||
// var_dump($line);
|
||||
}
|
||||
|
||||
function pdf($smarty) {
|
||||
include_once ("include/MPDF60/mpdf60/mpdf.php");
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
|
||||
$EcmSysInfos = new EcmSysInfo();
|
||||
|
||||
if(!$_REQUEST['date_from']) {
|
||||
$date_from = date("01.m.Y");
|
||||
} else {
|
||||
$date_from = $_REQUEST["date_from"];
|
||||
}
|
||||
|
||||
if(!$_REQUEST['date_to']) {
|
||||
$date_to = date("d.m.Y");
|
||||
} else {
|
||||
$date_to = $_REQUEST["date_to"];
|
||||
}
|
||||
|
||||
|
||||
$content = $smarty->fetch('modules/EcmReports/tpls/ReportSalesByGroupPDF.tpl');
|
||||
$mPDF = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 10, 10, 5, 5 );
|
||||
$mPDF->mirrorMargins = 1;
|
||||
$mPDF->WriteHTML($content);
|
||||
|
||||
$dir = 'upload/' . $EcmSysInfos->getDatabaseName() . '/pdf/EcmReports/';
|
||||
if(!is_dir($dir)){
|
||||
mkdir($dir, '755', true);
|
||||
}
|
||||
$file_name = str_replace(".","",$date_from) . "_" . str_replace(".","",$date_to) ."_Raport_Sprzedazy_Po_Gropach.pdf";
|
||||
$mPDF->Output( $file_name, "F");
|
||||
|
||||
print $file_name;
|
||||
}
|
||||
|
||||
function chart_json($table_result_array, $group_ks) {
|
||||
|
||||
// header('Content-Type: application/json');
|
||||
|
||||
$head = $group_ks;
|
||||
$body = $table_result_array;
|
||||
|
||||
// $arr = [];
|
||||
|
||||
$arr = [
|
||||
['Year', 'Month', 'Money'],
|
||||
[2016, 12, '12.55'],
|
||||
[2015, 01, '01.35'],
|
||||
];
|
||||
|
||||
/*$arr['cols'] = [
|
||||
[
|
||||
'id' => 'month',
|
||||
'label' => 'Month',
|
||||
'type' => 'string'
|
||||
],
|
||||
[
|
||||
'id' => 'year',
|
||||
'label' => 'YEAR',
|
||||
'type' => 'date'
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
$arr['rows'] = [
|
||||
'v' => '2016',
|
||||
'v' => '2016',
|
||||
'v' => '2016',
|
||||
'v' => '2016',
|
||||
'v' => '2016',
|
||||
'c' => '2016',
|
||||
'c' => '2016',
|
||||
'c' => '2016',
|
||||
];*/
|
||||
|
||||
/*$arr['cols'][] = [
|
||||
'id' => 'year',
|
||||
'label' => 'YEAR',
|
||||
'type' => 'date'
|
||||
];
|
||||
|
||||
$arr['cols'][] = [
|
||||
'id' => 'value',
|
||||
'label' => 'value',
|
||||
'type' => 'number'
|
||||
];
|
||||
|
||||
foreach($head as $head_key => $head_val) {
|
||||
$arr['cols'][] = [
|
||||
'id' => $head_key,
|
||||
'label' => $head_val,
|
||||
'type' => 'string'
|
||||
];
|
||||
}
|
||||
|
||||
foreach($body as $body_key => $body_val) {
|
||||
$arr['rows'][] = [
|
||||
'v' => $body_val['ecminvoiceouts_year'],
|
||||
];
|
||||
}*/
|
||||
|
||||
echo json_encode($arr);
|
||||
}
|
||||
|
||||
function generate_header($group_ks) {
|
||||
$header = [];
|
||||
|
||||
$header[] = 'ROK';
|
||||
$header[] = 'MIESIĄC';
|
||||
$header[] = 'PROFIL GŁÓWNY';
|
||||
$header[] = 'ILU ODBIORCÓW W LICZBACH';
|
||||
$header[] = 'ILE DOKUMENTÓW';
|
||||
|
||||
foreach ($group_ks as $list_group_k) { $header[] = $list_group_k; }
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
/*function _generate_line($group_ks, $table_result_array, $array_months, $types) {
|
||||
|
||||
$line = [];
|
||||
|
||||
foreach ($table_result_array as $key => $val) {
|
||||
$line[$key]['ecminvoiceouts_year'] = $val['ecminvoiceouts_year'];
|
||||
$line[$key]['ecminvoiceouts_month'] = $array_months[ $val['ecminvoiceouts_month'] ];
|
||||
$line[$key]['accounts_type'] = $types[ $val['accounts_type'] ];
|
||||
$line[$key]['accounts_count'] = $val['accounts_count'];
|
||||
$line[$key]['ecminvoiceouts_count'] = $val['ecminvoiceouts_count'];
|
||||
|
||||
foreach ($group_ks as $group_ks_key => $group_ks_val) {
|
||||
if($group_ks_key == $val['ecmproducts_group_ks']) {
|
||||
$line[$key][] = $val['ecminvoiceouts_total_brutto'];
|
||||
} else {
|
||||
$line[$key][] = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $line;
|
||||
}*/
|
||||
|
||||
function generate_line($group_ks, $table_result_array, $array_months, $types, $generate_table_array) {
|
||||
$line = [];
|
||||
|
||||
foreach ($generate_table_array as $year_key => $year) {
|
||||
foreach ($year as $month_key => $month) {
|
||||
foreach ($month as $type_key => $type) {
|
||||
|
||||
$line[$year_key."_".$month_key."_".$type_key]['ecminvoiceouts_year'] = $year_key;
|
||||
$line[$year_key."_".$month_key."_".$type_key]['ecminvoiceouts_month'] = $array_months[$month_key];
|
||||
$line[$year_key."_".$month_key."_".$type_key]['accounts_type'] = $types[$type_key];
|
||||
$line[$year_key."_".$month_key."_".$type_key]['accounts_count'] = $type['accounts_count'];
|
||||
$line[$year_key."_".$month_key."_".$type_key]['documents_count'] = $type['documents_count'];
|
||||
|
||||
foreach ($group_ks as $groups_key => $groups) {
|
||||
$count=0;
|
||||
|
||||
foreach ($type['accounts_type'] as $group_key => $group) {
|
||||
if($groups_key == $group_key) {
|
||||
$count=1;
|
||||
$line[$year_key."_".$month_key."_".$type_key][$group_key] = number_format($group);
|
||||
}
|
||||
}
|
||||
|
||||
if($count == 0) {
|
||||
$line[$year_key."_".$month_key."_".$type_key][$group_key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
function coding_pl($variable) {
|
||||
return preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/", ' ', preg_replace("/\r\n|\r|\n/", ' ', html_entity_decode($variable)));
|
||||
}
|
||||
|
||||
function coding($data) {
|
||||
foreach ($data as $k=>$v){
|
||||
$data[$k]=iconv('UTF-8', 'windows-1250', $data[$k]);;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("APP_LIST_STRINGS", $app_list_strings);
|
||||
|
||||
$smarty->assign("table_array", $generate_table_array);
|
||||
|
||||
$smarty->assign("list_types", $types);
|
||||
$smarty->assign("list_group_ks", $group_ks);
|
||||
|
||||
$smarty->assign("list_years", $years);
|
||||
$smarty->assign("list_months", $months);
|
||||
|
||||
$smarty->assign("months", $array_months);
|
||||
|
||||
$_REQUEST['to_xls'] = isset($_REQUEST['to_xls']) ? $_REQUEST['to_xls'] : null;
|
||||
$_REQUEST['to_json'] = isset($_REQUEST['to_json']) ? $_REQUEST['to_json'] : null;
|
||||
$_REQUEST['to_pdf_gen'] = isset($_REQUEST['to_pdf_gen']) ? $_REQUEST['to_pdf_gen'] : null;
|
||||
$_REQUEST['to_chart'] = isset($_REQUEST['to_chart']) ? $_REQUEST['to_chart'] : null;
|
||||
|
||||
if($_REQUEST['to_xls'] == '1') {
|
||||
xsl($group_ks, $table_result_array, $array_months, $types, $generate_table_array);
|
||||
} elseif($_REQUEST['to_pdf_gen'] == '1') {
|
||||
pdf($smarty);
|
||||
} elseif($_REQUEST['to_json'] == '1') {
|
||||
chart_json($table_result_array, $group_ks);
|
||||
// print "JSON";
|
||||
} elseif($_REQUEST['to_chart'] == '1') {
|
||||
echo $smarty->display('modules/EcmReports/tpls/ReportSalesByGroupChart.tpl');
|
||||
} else {
|
||||
echo $smarty->display('modules/EcmReports/tpls/ReportSalesByGroup.tpl');
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
global $mod_strings, $app_list_strings, $db;
|
||||
|
||||
if(!$_REQUEST['date_from'])
|
||||
$date_from = date("01.m.Y");
|
||||
else
|
||||
$date_from = $_REQUEST["date_from"];
|
||||
|
||||
if(!$_REQUEST['date_to'])
|
||||
$date_to = date("d.m.Y");
|
||||
else
|
||||
$date_to = $_REQUEST["date_to"];
|
||||
|
||||
if(!class_exists('EcmInvoiceOut')){
|
||||
include_once('modules/EcmInvoiceouts/EcmInvoiceout.php');
|
||||
};
|
||||
if(!class_exists('EcmReceipts')){
|
||||
include_once('modules/EcmReceipts/EcmReceipt.php');
|
||||
};
|
||||
|
||||
//get trader list
|
||||
$query_trader = "select ecminvoiceouts.assigned_user_id AS user_id , concat(users.first_name, ' ', users.last_name) AS user_name FROM ecminvoiceouts, users WHERE ecminvoiceouts.deleted = 0 and ecminvoiceouts.canceled = 0 AND users.id = ecminvoiceouts.assigned_user_id group by user_id ORDER BY user_name";
|
||||
$trader_result = $db->query($query_trader);
|
||||
$trader_array = array(""=>"");
|
||||
while($row = $db->fetchByAssoc($trader_result)){
|
||||
$trader_array[$row['user_id']] = $row['user_name'];
|
||||
}
|
||||
|
||||
//Get Stock List
|
||||
|
||||
$query_stock = "Select id, name from ecmstocks where deleted=0";
|
||||
$stock_result = $db->query($query_stock);
|
||||
$stock_array = array(""=>"");
|
||||
while($row = $db->fetchByAssoc($stock_result)){
|
||||
$stock_array[$row['id']] = $row['name'];
|
||||
}
|
||||
|
||||
|
||||
//Szykowanie zapytań
|
||||
//Zakres dat
|
||||
$whereInvoice['ecminvoiceouts'][] = 'register_date>="' . getFormatedDateForDB($date_from) . '"';
|
||||
$whereInvoice['ecminvoiceouts'][] = 'register_date<="' . getFormatedDateForDB($date_to) . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'register_date>="' . getFormatedDateForDB($date_from) . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'register_date<="' . getFormatedDateForDB($date_to) . '"';
|
||||
//Handlowiec
|
||||
if($_REQUEST['trader'] != ""){
|
||||
$whereInvoice['ecminvoiceouts'][] = 'assigned_user_id="' . $_REQUEST['trader'] . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'assigned_user_id="' . $_REQUEST['trader'] . '"';
|
||||
}
|
||||
//Kontrahent
|
||||
if($_REQUEST['account_id'] != ""){
|
||||
$whereInvoice['ecminvoiceouts'][] = 'parent_id="' . $_REQUEST['account_id'] . '"';
|
||||
$whereRecipe['ecmrecipes'][] = 'parent_id="' . $_REQUEST['account_id'] . '"';
|
||||
}
|
||||
//Magazyn
|
||||
$stocks = $_REQUEST['stocks'];
|
||||
if(count($stocks)>0){
|
||||
if(in_array("",$stocks)){
|
||||
$indeks = array_search("",$stocks);
|
||||
unset($stocks[$indeks]);
|
||||
}
|
||||
if(count($stocks)>0){
|
||||
$stocksList = array();
|
||||
$value = array_values ( $stocks );
|
||||
$whereInvoice['ecminvoiceouts'][] = 'stock_id IN ("' . implode('","',$value) . '")';
|
||||
$whereRecipe['ecmrecipes'][] = 'stock_id IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
//Grupa
|
||||
$product_group = $_REQUEST['product_group'];
|
||||
if(count($product_group)>0){
|
||||
if(in_array("",$product_group)){
|
||||
$indeks = array_search("",$product_group);
|
||||
unset($product_group[$indeks]);
|
||||
}
|
||||
if(count($product_group)>0){
|
||||
$product_group_list = array();
|
||||
$value = array_values ( $product_group );
|
||||
$whereInvoice['ecmproducts'][] = 'ks_group IN ("' . implode('","',$value) . '")';
|
||||
$whereRecipe['ecmproducts'][] = 'ks_group IN ("' . implode('","',$value) . '")';
|
||||
}
|
||||
}
|
||||
|
||||
//Typ dokumentu
|
||||
$document_sales_type = $_REQUEST['document_sales_type'];
|
||||
if(count($document_sales_type)>0){
|
||||
if(in_array("",$document_sales_type)){
|
||||
$indeks = array_search("",$document_sales_type);
|
||||
unset($document_sales_type[$indeks]);
|
||||
}
|
||||
|
||||
if(count($document_sales_type)>0){
|
||||
$tmpInvoiceType = array();
|
||||
$tmpRecipeType = array();
|
||||
$receiptDo = false;
|
||||
$invoceDo = true;
|
||||
foreach($document_sales_type as $key => $value){
|
||||
switch($value){
|
||||
case 'invoice':
|
||||
$tmpInvoiceType[] = 'normal';
|
||||
$invoceDo = true;
|
||||
break;
|
||||
case 'invoice_correct':
|
||||
$invoceDo = true;
|
||||
$tmpInvoiceType[] = 'correct';
|
||||
break;
|
||||
case 'recipe':
|
||||
$receiptDo = true;
|
||||
$tmpRecipeType[] = 'normal';
|
||||
break;
|
||||
case 'recipe_correct':
|
||||
$receiptDo = true;
|
||||
$tmpRecipeType[] = 'correct';
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(count($tmpInvoiceType)>0){
|
||||
$value = array_values ( $tmpInvoiceType );
|
||||
$whereInvoice['ecminvoiceouts'][] = 'type IN ("' . implode('","',$value) . '")';
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
}
|
||||
|
||||
if(count($tmpRecipeType)>0){
|
||||
$value = array_values ( $tmpRecipeType );
|
||||
$whereRecipe['ecmrecipes'][] = 'type IN ("' . implode('","',$value) . '")';
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
|
||||
}else{
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
}else{
|
||||
$dataInvoice = EcmInvoiceOut::getInvoiceList($whereInvoice);
|
||||
$dataRecipe = EcmReceipt::getReceiptsList($whereRecipe);
|
||||
}
|
||||
|
||||
// Przetwarzanie danych
|
||||
$data = array();
|
||||
foreach($dataInvoice as $indeks => $invoice){
|
||||
foreach($invoice['position_list'] as $position => $item){
|
||||
|
||||
$data[$item['product_id']]['name'] = '<a target="_blank" href="index.php?module=EcmProducts&return_module=EcmProducts&action=DetailView&parentTab=Produkty&record=' . $item['product_id'] . '">' . $item['position_code'] . ' ' . $item['position_name'] . '</a>';
|
||||
$data[$item['product_id']]['total_netto'] += $item['position_total_netto'];
|
||||
$data[$item['product_id']]['price_purchase'] += $item['position_total_price_purchase'];
|
||||
$data[$item['product_id']]['quantity'] += $item['position_quantity'];
|
||||
$data[$item['product_id']]['jm_precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$item['position_unit_id']];
|
||||
$data[$item['product_id']]['jm_name'] = $item['position_unit_name'];
|
||||
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$data[$item['product_id']]['name'] =$item['position_code'] . ' ' . $item['position_name'];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($dataRecipe as $indeks => $invoice){
|
||||
foreach($invoice['position_list'] as $position => $item){
|
||||
$data[$item['product_id']]['name'] = '<a target="_blank" href="index.php?module=EcmProducts&return_module=EcmProducts&action=DetailView&parentTab=Produkty&record=' . $item['product_id'] . '">'. $item['position_code'] . ' ' . $item['position_name'] . '</a>';
|
||||
$data[$item['product_id']]['total_netto'] += $item['position_total_netto'];
|
||||
$data[$item['product_id']]['price_purchase'] += $item['position_total_price_purchase'];
|
||||
$data[$item['product_id']]['quantity'] += $item['position_quantity'];
|
||||
$data[$item['product_id']]['jm_precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$item['position_unit_id']];
|
||||
$data[$item['product_id']]['jm_name'] = $item['position_unit_name'];
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$data[$item['product_id']]['name'] =$item['position_code'] . ' ' . $item['position_name'];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//var_dump($data);
|
||||
//
|
||||
//Szykowanie wyświetlania
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("APP_LIST_STRINGS", $app_list_strings);
|
||||
$smarty->assign("DATA", $data);
|
||||
$smarty->assign("TRADERS_LIST", $trader_array);
|
||||
$smarty->assign("STOCK_LIST", $stock_array);
|
||||
|
||||
|
||||
//Ustawiamy przeslane dane
|
||||
//$date_from = $GLOBALS['timedate']->to_display_date($date_from);
|
||||
//$date_to = $GLOBALS['timedate']->to_display_date($date_to);
|
||||
$smarty->assign("date_from_value", $date_from );
|
||||
$smarty->assign("date_to_value", $date_to );
|
||||
$smarty->assign("TRADER_SELECTED", $_REQUEST['trader']);
|
||||
$smarty->assign("ACCOUNT_ID", $_REQUEST['account_id']);
|
||||
$smarty->assign("ACCOUNT_NAME", $_REQUEST['account_name']);
|
||||
|
||||
if($_REQUEST['to_pdf']!='1'){
|
||||
$smarty->assign("STOCK_SELECTED", $_REQUEST['stocks']);
|
||||
$smarty->assign("PRODUCT_GROUP_SELECTED", $_REQUEST['product_group']);
|
||||
$smarty->assign("DOCUMENT_SALES_SELECTED", $_REQUEST['document_sales_type']);
|
||||
echo $smarty->display('modules/EcmReports/tpls/ReportSalesByProduct.tpl');
|
||||
|
||||
}else{
|
||||
if($_REQUEST['to_xls']=='1'){
|
||||
$header=array();
|
||||
$header[]='nazwa';
|
||||
$header[]='ilość';
|
||||
$header[]='jm';
|
||||
$header[]='sprzedaż netto';
|
||||
$header[]='koszt zakupu';
|
||||
$header[]='dochód';
|
||||
$filename='modules/Home/Files/raport_sprzedazy_ilosciowy_'.date('d_m_Y').'.csv';
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
foreach ($data as $key=>$val){
|
||||
$line=array();
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['name'])));
|
||||
$line[]=str_replace(".",",",$val['quantity']);
|
||||
$line[]=$val['jm_name'];
|
||||
$line[]=str_replace(".",",",$val['total_netto']);
|
||||
$line[]=str_replace(".",",",$val['price_purchase']);
|
||||
$line[]=str_replace(".",",",$val['total_netto']-$val['price_purchase']);
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
print $filename;
|
||||
} else {
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
$smarty->assign("STOCK_SELECTED", $stocks);
|
||||
$smarty->assign("PRODUCT_GROUP_SELECTED", $product_group);
|
||||
$smarty->assign("DOCUMENT_SALES_SELECTED", $document_sales_type);
|
||||
|
||||
$EcmSysInfo = new EcmSysInfo();
|
||||
$smarty->assign("EcmSysInfo", $EcmSysInfo);
|
||||
//echo $EcmSysInfo->getName();
|
||||
|
||||
$content = $smarty->fetch('modules/EcmReports/tpls/ReportSalesByProductPDF.tpl');
|
||||
$mPDF = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 10, 10, 5, 5 );
|
||||
$mPDF->mirrorMargins = 1;
|
||||
$mPDF->WriteHTML($content);
|
||||
$dir = 'upload/' . $EcmSysInfo->getDatabaseName() . '/pdf/EcmReports/';
|
||||
if(!is_dir($dir)){
|
||||
mkdir($dir, '755', true);
|
||||
}
|
||||
$file_name = $dir . str_replace(".","",$date_from) . "_" . str_replace(".","",$date_to) ."_Raport_Sprzedazy_Ilosciowy.pdf";
|
||||
$mPDF->Output( $file_name, "F");
|
||||
print $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
function getFormatedDateForDB($data){
|
||||
if(strpos($data,".")>0){
|
||||
$split = explode (".",$data);
|
||||
$return_data = $split[2] . "-" . $split[1] . "-" .$split['0'];
|
||||
}
|
||||
return $return_data;
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
/*
|
||||
* author: Michał Zieliński, mz@bim-it.pl
|
||||
* created: 12.08.2015
|
||||
* last modified date: 10.09.2015 by MZ
|
||||
*/
|
||||
global $mod_strings;
|
||||
$process = false;
|
||||
if ($_REQUEST['process'] == "1") $process = true;
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
//create search form
|
||||
$ss = new Sugar_Smarty ();
|
||||
$ss->assign("MOD", $mod_strings);
|
||||
//group accounts
|
||||
if ($_REQUEST['group_accounts'] == "on") {
|
||||
$group_accounts = true;
|
||||
$ss->assign("GROUP_ACCOUNTS", "1");
|
||||
}
|
||||
//get Stocks
|
||||
$stocks = "";
|
||||
if ($_REQUEST['stocks']) $stocks = $_REQUEST['stocks'];
|
||||
$s_res = $db->query("SELECT id, name FROM ecmstocks WHERE deleted='0' ORDER BY name");
|
||||
$stocks_tpl = '<select multiple id="stocks" name="stocks[]">';
|
||||
$s_stocks = "";
|
||||
while ($s_row = $db->fetchByAssoc($s_res)) {
|
||||
$stocks_tpl .= '<option value="'.$s_row['id'].'"';
|
||||
if ($stocks=="" || in_array($s_row['id'], $stocks)) {
|
||||
$stocks_tpl .= " selected ";
|
||||
$s_stocks.= $s_row['name'].", ";
|
||||
}
|
||||
$stocks_tpl .= '>'.$s_row['name'].'</option>';
|
||||
}
|
||||
$stocks_tpl .= '</select>';
|
||||
$s_stocks = substr($s_stocks,0,-2);
|
||||
if (is_array($stocks) && sizeof($stocks) == $s_res->num_rows)
|
||||
$s_stocks = "Wszystkie";
|
||||
$ss->assign("STOCKS", $stocks_tpl);
|
||||
//document types
|
||||
$types_def = array (
|
||||
'FV' => 'Faktura',
|
||||
'FVKOR' => 'Faktura korygująca',
|
||||
//'REC' => 'Paragon',
|
||||
//'RECKOR' => 'Korekta paragonu',
|
||||
);
|
||||
$types = "";
|
||||
if ($_REQUEST['types']) $types = $_REQUEST['types'];
|
||||
$s_types = "";
|
||||
$types_tpl = '<select multiple id="types" name="types[]">';
|
||||
foreach ($types_def as $k=>$v) {
|
||||
$types_tpl .= '<option value="'.$k.'"';
|
||||
if ($types == "" || in_array($k, $types)) {
|
||||
$types_tpl .= ' selected';
|
||||
$s_types .= $v.", ";
|
||||
}
|
||||
$types_tpl .= '>'.$v.'</option>';
|
||||
}
|
||||
$types_tpl .= '</select>';
|
||||
$s_types = substr($s_types, 0, -2);
|
||||
if (is_array($types) && sizeof($types) == sizeof($types_def))
|
||||
$s_types = "Wszystkie";
|
||||
|
||||
$ss->assign("TYPES", $types_tpl);
|
||||
//document kinds
|
||||
$kinds_def = array (
|
||||
'K' => 'Kraj',
|
||||
'U' => 'Unia',
|
||||
'E' => 'Eksport',
|
||||
);
|
||||
$kinds = "";
|
||||
if ($_REQUEST['kinds']) $kinds = $_REQUEST['kinds'];
|
||||
$s_kinds = "";
|
||||
$kinds_tpl = '<select multiple id="kinds" name="kinds[]">';
|
||||
foreach ($kinds_def as $k=>$v) {
|
||||
$kinds_tpl .= '<option value="'.$k.'"';
|
||||
if ($kinds == "" || in_array($k, $kinds)) {
|
||||
$kinds_tpl .= ' selected';
|
||||
$s_kinds.=$v.", ";
|
||||
}
|
||||
$kinds_tpl .= '>'.$v.'</option>';
|
||||
}
|
||||
$kinds_tpl .= '</select>';
|
||||
$s_kinds = substr($s_kinds,0,-2);
|
||||
if (is_array($kinds) && sizeof($kinds) == sizeof($kinds_def))
|
||||
$s_kinds = "Wszystkie";
|
||||
$ss->assign("KINDS", $kinds_tpl);
|
||||
//document categories
|
||||
$categories = "";
|
||||
if ($_REQUEST['categories']) $categories = $_REQUEST['categories'];
|
||||
$s_categories = "";
|
||||
global $app_list_strings;
|
||||
$z=$GLOBALS['db']->query('select id,name from ecminvoicecategories');
|
||||
$categories_def=array();
|
||||
while($cat=$GLOBALS['db']->fetchByAssoc($z)){
|
||||
$categories_def[$cat['id']]=$cat['name'];
|
||||
}
|
||||
//$categories_def = $app_list_strings['ecminvoiceouts_category_dom'];
|
||||
if ($_REQUEST['categories']) $categories = $_REQUEST['categories'];
|
||||
$categories_tpl = '<select multiple id="categories" name="categories[]">';
|
||||
$categories_tpl.='<option value="all" selected></option>';
|
||||
foreach ($categories_def as $k=>$v) {
|
||||
$categories_tpl .= '<option value="'.$k.'"';
|
||||
if ($categories == "" || in_array($k, $categories)) {
|
||||
//$categories_tpl .= ' selected';
|
||||
$s_categories.= $v.", ";
|
||||
}
|
||||
$categories_tpl .= '>'.$v.'</option>';
|
||||
}
|
||||
$categories_tpl .= '</select>';
|
||||
$s_categories = substr($s_categories,0,-2);
|
||||
if (is_array($categories) && sizeof($categories) == sizeof($categories_def)) {
|
||||
$s_categories = "Wszystkie";
|
||||
}
|
||||
$ss->assign("CATEGORIES", $categories_tpl);
|
||||
//dates
|
||||
if ($_REQUEST['date_from'])
|
||||
$date_from = $_REQUEST['date_from'];
|
||||
else {
|
||||
$date_from = new DateTime("first day of last month");
|
||||
$date_from = $date_from->format('d.m.Y');
|
||||
}
|
||||
$date_from_db = implode('-', array_reverse(explode('.', $date_from)));
|
||||
|
||||
$ss->assign("DATE_FROM", $date_from);
|
||||
|
||||
if ($_REQUEST['date_to'])
|
||||
$date_to = $_REQUEST['date_to'];
|
||||
else {
|
||||
$date_to = new DateTime("last day of last month");
|
||||
$date_to = $date_to->format('d.m.Y');
|
||||
}
|
||||
$date_to_db = implode('-', array_reverse(explode('.', $date_to)));
|
||||
$ss->assign("DATE_TO", $date_to);
|
||||
|
||||
if (!$process == true) {
|
||||
$ss->display ( 'modules/EcmReports/tpls/ReportSalesVatSales.tpl' );
|
||||
return;
|
||||
}
|
||||
|
||||
//Do your job!
|
||||
$main_query = "SELECT id, total_netto, total_brutto, total_vat, vats_summary, purchase_price FROM ecminvoiceouts WHERE deleted='0' AND canceled='0'";
|
||||
$main_query.= "AND register_date >= '$date_from_db' AND register_date <= '$date_to_db' ";
|
||||
if (in_array("FV", $types) && !in_array("FVKOR", $types))
|
||||
$main_query .= "AND type='normal' ";
|
||||
if (in_array("FVKOR", $types) && ! in_array("FV", $types))
|
||||
$main_query .= "AND type='correct' ";
|
||||
if (is_array($stocks))
|
||||
$main_query .= " AND stock_id IN ('".implode("','", $stocks)."') ";
|
||||
|
||||
if($_REQUEST['categories'][0]=='all'){
|
||||
$s_categories = "Wszystkie";
|
||||
} else {
|
||||
if (is_array($categories))
|
||||
$main_query .= " AND (category IN ('".implode("','", $categories)."') OR category IS NULL)";
|
||||
}
|
||||
|
||||
if (is_array($kinds))
|
||||
$main_query .= " AND pdf_type IN ('".implode("','", $kinds)."') ";
|
||||
$main_query .= " ORDER BY register_date, date_entered";
|
||||
|
||||
//echo $main_query; die();
|
||||
//echo $main_query;
|
||||
$inv_res = $db->query($main_query);
|
||||
|
||||
//get vats names
|
||||
$main_query = str_replace(", total_netto, total_brutto, total_vat, vats_summary, purchase_price", "", $main_query); //leave only id field
|
||||
$vats_query = "SELECT distinct ii.ecmvat_name, v.value FROM ecminvoiceoutitems AS ii
|
||||
INNER JOIN ecmvats as v
|
||||
ON v.id = ii.ecmvat_id
|
||||
WHERE ecminvoiceout_id IN ($main_query) order by ecmvat_value";
|
||||
$v_res = $db->query($vats_query);
|
||||
$vats = array();
|
||||
$vatsCount = 0;
|
||||
while ($v_row = $db->fetchByAssoc($v_res)) {
|
||||
//check if value is 0
|
||||
if ($v_row['value'] == 0) {
|
||||
$vats[$v_row['ecmvat_name']] = 1; //var is 0 - we didn't have to draw column
|
||||
$vatsCount++;
|
||||
} else {
|
||||
$vats[$v_row['ecmvat_name']] = 2;
|
||||
$vatsCount+=2;
|
||||
}
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$c = 1; //counter
|
||||
while ($row = $db->fetchByAssoc($inv_res)) {
|
||||
$tmp = array();
|
||||
$tmp['lp'] = $c; $c++;
|
||||
$inv = new EcmInvoiceOut();
|
||||
$inv->retrieve($row['id']);
|
||||
$tmp['document_no'] = $inv->document_no;
|
||||
if($inv->type=='correct'){
|
||||
$tmp['document_no'] = 'KF '.$inv->document_no;
|
||||
} else {
|
||||
$tmp['document_no'] = 'FV '.$inv->document_no;
|
||||
}
|
||||
$tmp['register_date'] = $inv->register_date;
|
||||
//$pi = $inv->parent_nip.", ".$inv->parent_name.", ".$inv->parent_address_street.", ".$inv->parent_address_postalcode.", ".$inv->parent_address_city;
|
||||
$pi = $inv->parent_nip;
|
||||
if (strlen($pi.", ".$inv->parent_name) <= 80){
|
||||
$pi.=", ".$inv->parent_name;
|
||||
} else {
|
||||
|
||||
$pos=strpos($inv->parent_name," ");
|
||||
|
||||
if($pos !== false){
|
||||
$inv->parent_name=substr($inv->parent_name, 0,$pos).('...');
|
||||
}
|
||||
$pi.=", ".$inv->parent_name;
|
||||
}
|
||||
|
||||
if (strlen($pi.", ".$inv->parent_address_street) <= 80){
|
||||
$pi.=", ".$inv->parent_address_street;
|
||||
}
|
||||
if (strlen($pi.", ".$inv->parent_address_postalcode) <= 80)
|
||||
$pi.=", ".$inv->parent_address_postalcode;
|
||||
if (strlen($pi.", ".$inv->parent_address_city) <= 80)
|
||||
$pi.=", ".$inv->parent_address_city;
|
||||
$tmp['parent_info'] = $pi;
|
||||
$a = new Account();
|
||||
$a->retrieve($inv->parent_id);
|
||||
$tmp['parent_index'] = $a->index_dbf;
|
||||
$tmp['parent_id'] = $a->id;
|
||||
unset($a);
|
||||
|
||||
if ($inv->currency_id == 'PLN') $currency = 1; else $currency = $inv->currency_value_nbp;
|
||||
$tmp['netto'] = round($row['total_netto'] * $currency,2);
|
||||
$tmp['brutto'] = round($row['total_brutto'] * $currency,2);
|
||||
$tmp['vat'] = round($row['total_vat'] * $currency,2);
|
||||
$tmp['type']=$inv->type;
|
||||
if($inv->type=='correct'){
|
||||
$tmp['purchase'] = -1*$row['purchase_price'];
|
||||
} else {
|
||||
$tmp['purchase'] = $row['purchase_price'];
|
||||
}
|
||||
|
||||
//prepare vats
|
||||
$vat_tmp = array();
|
||||
$v_tmp = explode(",", $row['vats_summary']);
|
||||
$v_tmp = array_slice($v_tmp, 0, -1); //remove last empty element
|
||||
foreach ($v_tmp as $val) {
|
||||
$vv_tmp = explode(":", $val);
|
||||
$vvv_tmp = array();
|
||||
$vvv_tmp[] = $vv_tmp[1];
|
||||
$vvv_tmp[] = $vv_tmp[2];
|
||||
$vat_tmp[$vv_tmp[0]] = $vvv_tmp;
|
||||
unset($vvv_tmp);
|
||||
unset($vv_tmp);
|
||||
}
|
||||
unset($v_tmp);
|
||||
$inv_vat = array();
|
||||
foreach ($vats as $k => $v) {
|
||||
$tmp_vat = array();
|
||||
if (is_array($vat_tmp[$k])) {
|
||||
$tmp_vat[] = round($vat_tmp[$k][0]*$currency,2);
|
||||
$tmp_vat[] = round($vat_tmp[$k][1]*$currency,2);
|
||||
} else {
|
||||
$tmp_vat[] = 0;
|
||||
$tmp_vat[] =0;
|
||||
}
|
||||
$inv_vat[$k] = $tmp_vat;
|
||||
unset($tmp_vat);
|
||||
}
|
||||
$tmp['vats'] = $inv_vat;
|
||||
unset($inv_vat);
|
||||
unset($inv);
|
||||
$data[] = $tmp;
|
||||
unset($tmp);
|
||||
}
|
||||
|
||||
|
||||
if ($group_accounts == true) {
|
||||
usort($data, "cmp");
|
||||
//creaate Accounts summary
|
||||
$tmp_data = array();
|
||||
$summary = array();
|
||||
$sum = array();
|
||||
$sum_vat = array();
|
||||
for ($i = 0; $i < sizeof($data); $i++) {
|
||||
$row = $data[$i];
|
||||
$row['lp'] = $i+1;
|
||||
$tmp_data[] = $row;
|
||||
if (array_key_exists("total_netto",$sum))
|
||||
$sum['total_netto'] += $row['netto']; else $sum['total_netto'] = $row['netto'];
|
||||
if (array_key_exists("total_brutto",$sum))
|
||||
$sum['total_brutto'] += $row['brutto']; else $sum['total_brutto'] = $row['brutto'];
|
||||
if (array_key_exists("total_vat",$sum))
|
||||
$sum['total_vat'] += $row['vat']; else $sum['total_vat'] = $row['vat'];
|
||||
if (array_key_exists("total_purchase",$sum))
|
||||
$sum['total_purchase'] += $row['purchase']; else $sum['total_purchase'] = $row['purchase'];
|
||||
foreach ($row['vats'] as $k=>$v) {
|
||||
if (!array_key_exists($k,$sum_vat)) {
|
||||
$sum_vat[$k][0] = 0;
|
||||
$sum_vat[$k][1] = 0;
|
||||
}
|
||||
$sum_vat[$k][0] += $v[0];
|
||||
$sum_vat[$k][1] += $v[1];
|
||||
}
|
||||
if ($data[$i]['parent_id'] != $data[$i+1]['parent_id'] || $i == sizeof($data)) {
|
||||
//insert summary row
|
||||
$sum['is_summary'] = 1;
|
||||
$sum['index'] = $row['parent_index'];
|
||||
$sum['parent_info'] = 'Podsumowanie dla kontrahenta';
|
||||
$sum['vats'] = $sum_vat;
|
||||
$tmp_data[] = $sum;
|
||||
unset($sum); $sum = array();
|
||||
unset($sum_vat); $sum_vat = array();
|
||||
}
|
||||
}
|
||||
$data = $tmp_data;
|
||||
}
|
||||
$datas=$data;
|
||||
$rop = 28; // rows on page
|
||||
$nop = ceil(sizeof($data)/$rop); // number of pages
|
||||
$pages_data = array_chunk($data, $rop);
|
||||
$pages = array();
|
||||
unset($data);
|
||||
$prev_page = array();
|
||||
$c = 1; //counter
|
||||
|
||||
foreach ($pages_data as $data) {
|
||||
$tmp = array();
|
||||
$tmp['site_netto'] = 0; $tmp['site_brutto'] = 0; $tmp['site_vat'] = 0; $tmp['site_purchase'] = 0;
|
||||
$tmp['moved_netto'] = 0; $tmp['moved_brutto'] = 0; $tmp['moved_vat'] = 0; $tmp['moved_purchase'] = 0;
|
||||
//prepare vats array
|
||||
$site_vats = array();
|
||||
$moved_vats = array();
|
||||
$total_vats = array();
|
||||
foreach ($vats as $k => $v) {
|
||||
$site_vats[$k][0] = 0;
|
||||
$site_vats[$k][1] = 0;
|
||||
$moved_vats[$k][0] = 0;
|
||||
$moved_vats[$k][1] = 0;
|
||||
$total_vats[$k][0] = 0;
|
||||
$total_vats[$k][1] = 0;
|
||||
}
|
||||
foreach ($data as $i) {
|
||||
$tmp['site_netto'] += $i['netto'];
|
||||
$tmp['site_brutto'] += $i['brutto'];
|
||||
$tmp['site_vat'] += $i['vat'];
|
||||
$tmp['site_purchase'] += $i['purchase'];
|
||||
foreach ($i['vats'] as $k => $v) {
|
||||
$site_vats[$k][0] += $v[0];
|
||||
$site_vats[$k][1] += $v[1];
|
||||
}
|
||||
}
|
||||
if ($c!=1) { //not first page
|
||||
$tmp['moved_netto'] = $prev_page['total_netto'];
|
||||
$tmp['moved_brutto'] = $prev_page['total_brutto'];
|
||||
$tmp['moved_vat'] = $prev_page['total_vat'];
|
||||
$tmp['moved_purchase'] = $prev_page['total_purchase'];
|
||||
|
||||
foreach ($vats as $k=>$v) {
|
||||
$moved_vats[$k][0] += $prev_page['total_vats'][$k][0];
|
||||
$moved_vats[$k][1] += $prev_page['total_vats'][$k][1];
|
||||
}
|
||||
}
|
||||
$tmp['total_netto'] = $tmp['site_netto'] + $tmp['moved_netto'];
|
||||
$tmp['total_brutto'] = $tmp['site_brutto'] + $tmp['moved_brutto'];
|
||||
$tmp['total_vat'] = $tmp['site_vat'] + $tmp['moved_vat'];
|
||||
$tmp['total_purchase'] = $tmp['site_purchase'] + $tmp['moved_purchase'];
|
||||
foreach ($vats as $k=>$v) {
|
||||
$total_vats[$k][0] += $site_vats[$k][0] + $moved_vats[$k][0];
|
||||
$total_vats[$k][1] += $site_vats[$k][1] + $moved_vats[$k][1];
|
||||
}
|
||||
//insert page data
|
||||
$tmp['rows'] = $data;
|
||||
$tmp['page_no'] = $c;
|
||||
$tmp['site_vats'] = $site_vats;
|
||||
$tmp['moved_vats'] = $moved_vats;
|
||||
$tmp['total_vats'] = $total_vats;
|
||||
|
||||
$pages[] = $tmp;
|
||||
$prev_page = $tmp;
|
||||
$c++;
|
||||
}
|
||||
//create document and show it
|
||||
|
||||
$ss_pdf = new Sugar_Smarty();
|
||||
$ss_pdf->assign("PAGES", $pages);
|
||||
|
||||
$ss_pdf->assign("VATS", $vats);
|
||||
$ss_pdf->assign("vatsCount", $vatsCount);
|
||||
//header stuff
|
||||
|
||||
$cur_date = new DateTime("now");
|
||||
$cur_date = $cur_date->format('d.m.Y H:m:s');
|
||||
$ss_pdf->assign("CUR_DATE", $cur_date);
|
||||
$ss_pdf->assign("DATE_FROM", $date_from);
|
||||
$ss_pdf->assign("DATE_TO", $date_to);
|
||||
$ss_pdf->assign("S_STOCK", $s_stocks);
|
||||
$ss_pdf->assign("S_KIND", $s_kinds);
|
||||
$ss_pdf->assign("S_CATEGORY", $s_categories);
|
||||
$ss_pdf->assign("S_TYPE", $s_types);
|
||||
if($_REQUEST['to_xls']==1){
|
||||
$header=array();
|
||||
$header[]='nr dok.';
|
||||
$header[]='data wystawienia';
|
||||
$header[]='odbiorca - nip,nazwa,adres';
|
||||
$header[]='sprzedaż brutto';
|
||||
$header[]='sprzedaż netto';
|
||||
foreach ($vats as $val){
|
||||
$header[]='netto '.$val;
|
||||
$header[]='vat '.$val;
|
||||
}
|
||||
$header[]='vat razem';
|
||||
$header[]='koszt';
|
||||
|
||||
$filename='modules/Home/Files/raport_sprzedazy_vat_'.date('d_m-Y').'.csv';
|
||||
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
|
||||
foreach ($pages[0]['rows'] as $key=>$val){
|
||||
|
||||
$line=array();
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['document_no']))).'"""';
|
||||
|
||||
$line[]=$val['register_date'];
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['parent_info'])));
|
||||
$line[]=str_replace(".",",",$val['brutto']);
|
||||
$line[]=str_replace(".",",",$val['netto']);
|
||||
foreach ($val['vats'] as $vi){
|
||||
$line[]=str_replace(".",",",$vi[0]);
|
||||
$line[]=str_replace(".",",",$vi[1]);
|
||||
}
|
||||
|
||||
$line[]=str_replace(".",",",$val['vat']);
|
||||
$line[]=str_replace(".",",",$val['purchase']);
|
||||
|
||||
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
header("Location: ". $filename);
|
||||
}else {
|
||||
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
$EcmSysInfo = new EcmSysInfo();
|
||||
$ss_pdf->assign("COMPANY_NAME", $EcmSysInfo->getName());
|
||||
$content = $ss_pdf->fetch ( 'modules/EcmReports/tpls/ReportSalesVatSalesPDF.tpl' );
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
$p = new mPDF ( '', 'A4', null, 'helvetica', 5, 5, 33, 5, 5, 5 );
|
||||
$p->writeHTML ($content) ;
|
||||
$p->setTitle ( "Rejestr sprzedaży VAT" );
|
||||
$p->output("rej.pdf", "I");
|
||||
}
|
||||
//helper
|
||||
function cmp($a, $b) {
|
||||
if ($a['parent_info'] == $b['parent_info']) {
|
||||
return ( $a['register_date'] > $b['register_date'] ) ? 1 : -1;
|
||||
}
|
||||
return ( $a['parent_info'] > $b['parent_info'] ) ? 1 : -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,532 @@
|
||||
<?php
|
||||
|
||||
ini_set('memory_limit', '-1');
|
||||
ini_set('max_execution_time', '-1');
|
||||
|
||||
if (!defined('sugarEntry') || !sugarEntry)
|
||||
die('Not A Valid Entry Point');
|
||||
|
||||
function getStocksList() {
|
||||
$db = $GLOBALS['db'];
|
||||
$queryStocks = "SELECT id, name FROM ecmstocks WHERE deleted= 0";
|
||||
$rowsStocks = $db->query($queryStocks);
|
||||
$stocks = array();
|
||||
while ($rowStocks = $db->fetchByAssoc($rowsStocks)) {
|
||||
$stocks [$rowStocks ["id"]] = $rowStocks ["name"];
|
||||
}
|
||||
return $stocks;
|
||||
}
|
||||
|
||||
function getStockIndexList() {
|
||||
$db = $GLOBALS['db'];
|
||||
$queryStockIndex = "SELECT id, name FROM ecmproductstockindexs;";
|
||||
$rowsStockIndex = $db->query($queryStockIndex);
|
||||
$StockIndexList = array();
|
||||
while ($rowStocksIndex = $db->fetchByAssoc($rowsStockIndex)) {
|
||||
$StockIndexList [$rowStocksIndex ["id"]] = $rowStocksIndex ["name"];
|
||||
}
|
||||
return $StockIndexList;
|
||||
}
|
||||
|
||||
function getKartotekaMaterialowaQuery($unknow) {
|
||||
if (!isset($unknow) || count($unknow) == 0 || (in_array('', $unknow))) {
|
||||
|
||||
} else {
|
||||
if (in_array('NULL', $unknow) && count($unknow) == 1) {
|
||||
$query .= " AND doc.ecmproductstockindex_id IS NULL ";
|
||||
} else if (in_array('NULL', $unknow) && count($unknow) > 1) {
|
||||
$queryUnknow = " (";
|
||||
foreach ($unknow as $key => $value) {
|
||||
if ($value != 'NULL') {
|
||||
$queryUnknow .= "'" . $value . "',";
|
||||
}
|
||||
}
|
||||
$queryUnknow = rtrim($queryUnknow, ",");
|
||||
$queryUnknow .= ") ";
|
||||
$query .= " AND (doc.ecmproductstockindex_id IS NULL OR doc.ecmproductstockindex_id IN " . $queryUnknow . ") ";
|
||||
} else {
|
||||
$queryUnknow = " (";
|
||||
foreach ($unknow as $key => $value) {
|
||||
$queryUnknow .= "'" . $value . "',";
|
||||
}
|
||||
$queryUnknow = rtrim($queryUnknow, ",");
|
||||
$queryUnknow .= ") ";
|
||||
$query .= " AND doc.ecmproductstockindex_id IN " . $queryUnknow . " ";
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Tworzy kawałek zapytania dla magazynów
|
||||
// np: ('magazyn1','magazyn2',...)
|
||||
function getStockQuery($stockSelected) {
|
||||
if (isset($stockSelected) && count($stockSelected) > 0) {
|
||||
$queryStockSelected = " (";
|
||||
foreach ($stockSelected as $key => $value) {
|
||||
$queryStockSelected .= "'" . $value . "',";
|
||||
}
|
||||
$queryStockSelected = rtrim($queryStockSelected, ",");
|
||||
$queryStockSelected .= ") ";
|
||||
} else {
|
||||
$stockList = getStocksList();
|
||||
$queryStockSelected = " (";
|
||||
foreach ($stockList as $key => $value) {
|
||||
$queryStockSelected .= "'" . $key . "',";
|
||||
}
|
||||
$queryStockSelected = rtrim($queryStockSelected, ",");
|
||||
$queryStockSelected .= ") ";
|
||||
}
|
||||
return $queryStockSelected;
|
||||
}
|
||||
|
||||
function getDataRwPwKs($documentsSelected, $stockSelected, $date_from, $date_to, $stockIndexSelected) {
|
||||
if (!isset($documentsSelected) && isset($stockSelected) && isset($date_from) && isset($date_to)) {
|
||||
return null;
|
||||
}
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
$documentsList = array(// dokumenty
|
||||
'EcmStockDocInsideOuts' => 'RW',
|
||||
'EcmStockDocInsideIns' => 'PW',
|
||||
'EcmStockDocMoves' => 'MM',
|
||||
'EcmStockDocCorrects' => 'KS',
|
||||
'EcmStockDocIns' => 'PZ',
|
||||
'EcmStockDocOuts' => 'WZ',
|
||||
'EcmInvoiceOuts' => "FK",
|
||||
'EcmReceipts' => 'Paragon'
|
||||
);
|
||||
|
||||
$query = "SELECT "
|
||||
. "doc.id AS docid, "
|
||||
. "doc.ecmproductstockindex_name AS docstockindex, "
|
||||
. "doc.name AS docname, "
|
||||
. "DATE_FORMAT(doc.register_date,'%d.%m.%Y') AS docregister_date, "
|
||||
. "doc.document_no AS docdocument_no, "
|
||||
. "doc.stock_id AS docstock_id, "
|
||||
. "o.type AS otype, "
|
||||
. "o.quantity AS oquantity, "
|
||||
. "o.price AS oprice, "
|
||||
. "o.product_id AS oproduct_id, "
|
||||
. "o.product_name AS oproduct_name, "
|
||||
. "o.product_code as oproduct_code, "
|
||||
. "p.unit_id as punit_id "
|
||||
. "FROM "
|
||||
. "ecmstockoperations o, "
|
||||
. "ecmproducts p, "
|
||||
. "" . strtolower($documentsSelected) . " doc "
|
||||
. "WHERE o.parent_id = doc.id "
|
||||
. "AND p.id = o.product_id "
|
||||
. "AND doc.deleted=0 "
|
||||
. "AND o.deleted=0 "
|
||||
. "AND doc.stock_id IN " . getStockQuery($stockSelected) . " "
|
||||
. "AND doc.register_date >='" . $date_from . "' "
|
||||
. "AND doc.register_date <= '" . $date_to . "'";
|
||||
$query .= getKartotekaMaterialowaQuery($stockIndexSelected);
|
||||
$query .= " ORDER BY doc.register_date, o.counter, o.product_code, o.product_name, doc.name";
|
||||
|
||||
$resultRows = $db->query($query);
|
||||
$stockList = getStocksList();
|
||||
while ($row = $db->fetchByAssoc($resultRows)) {
|
||||
if($documentsSelected=='EcmStockDocCorrects'){
|
||||
$c = new EcmStockDocCorrect();
|
||||
$c->retrieve($row['docid']);
|
||||
if($c->type=='6ed5b076-ddd1-9809-b236-54e5b2bcbd97'){
|
||||
if($row['otype']==0){
|
||||
$data['doc'][$row['docid']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
} else {
|
||||
$data['doc'][$row['docid']]['wartosc'] -= $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] -= $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['ilosc'] += $row['oquantity'];
|
||||
}
|
||||
|
||||
} else {
|
||||
$data['doc'][$row['docid']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['ilosc'] += $row['oquantity'];
|
||||
}
|
||||
|
||||
unset($c);
|
||||
} else {
|
||||
$data['doc'][$row['docid']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['ilosc'] += $row['oquantity'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
$data['prod'][$row['oproduct_id']]['kod'] = $row['oproduct_code'];
|
||||
$data['prod'][$row['oproduct_id']]['nazwa'] = $row['oproduct_name'];
|
||||
$data['prod'][$row['oproduct_id']]['id'] = $row['oproduct_id'];
|
||||
$data['prod'][$row['oproduct_id']]['data'] = $row['docregister_date'];
|
||||
$data['prod'][$row['oproduct_id']]['numer'] = $row['docdocument_no'];
|
||||
$data['prod'][$row['oproduct_id']]['kartoteka'] = $row['docstockindex'];
|
||||
$data['prod'][$row['oproduct_id']]['jm'] = $app_list_strings['ecmproducts_unit_dom'][$row['punit_id']];
|
||||
$data['doc'][$row['docid']]['magazyn'] = $stockList[$row['docstock_id']];
|
||||
$data['doc'][$row['docid']]['nazwa'] = $row['docname'];
|
||||
$data['doc'][$row['docid']]['typ'] = $documentsList[$documentsSelected];
|
||||
$data['doc'][$row['docid']]['id'] = $row['docid'];
|
||||
$data['doc'][$row['docid']]['data'] = $row['docregister_date'];
|
||||
$data['doc'][$row['docid']]['numer'] = $row['docdocument_no'];
|
||||
$data['doc'][$row['docid']]['kartoteka'] = $row['docstockindex'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function getDataMm($documentsSelected, $stockSelected, $date_from, $date_to, $mmSelected) {
|
||||
if (!isset($documentsSelected) && isset($stockSelected) && isset($date_from) && isset($date_to)) {
|
||||
return null;
|
||||
}
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
$documentsList = array(// dokumenty
|
||||
'EcmStockDocInsideOuts' => 'RW',
|
||||
'EcmStockDocInsideIns' => 'PW',
|
||||
'EcmStockDocMoves' => 'MM',
|
||||
'EcmStockDocCorrects' => 'KS',
|
||||
'EcmStockDocIns' => 'PZ',
|
||||
'EcmStockDocOuts' => 'WZ',
|
||||
'EcmInvoiceOuts' => "FK",
|
||||
'EcmReceipts' => 'Paragon'
|
||||
);
|
||||
|
||||
$query = "SELECT "
|
||||
. "doc.id AS docid, "
|
||||
. "doc.ecmproductstockindex_name AS docstockindex, "
|
||||
. "doc.name AS docname, "
|
||||
. "DATE_FORMAT(doc.register_date,'%d.%m.%Y') AS docregister_date, "
|
||||
. "doc.document_no AS docdocument_no, "
|
||||
. "doc.stock_in_id AS docstock_in_id,"
|
||||
. "doc.stock_out_id AS docstock_id,"
|
||||
. "o.type AS otype, "
|
||||
. "o.quantity AS oquantity, "
|
||||
. "o.price AS oprice, "
|
||||
. "o.product_id AS oproduct_id, "
|
||||
. "o.product_name AS oproduct_name, "
|
||||
. "o.product_code as oproduct_code, "
|
||||
. "p.unit_id as punit_id "
|
||||
. "FROM "
|
||||
. "ecmstockoperations o, "
|
||||
. "ecmproducts p, "
|
||||
. "" . strtolower($documentsSelected) . " doc "
|
||||
. "WHERE o.parent_id = doc.id "
|
||||
. "AND p.id = o.product_id "
|
||||
. "AND doc.deleted=0 "
|
||||
. "AND o.deleted=0 "
|
||||
. "AND doc.stock_out_id IN " . getStockQuery($stockSelected) . " "
|
||||
. "AND doc.stock_in_id IN " . getStockQuery($mmSelected) . " "
|
||||
. "AND doc.register_date >='" . $date_from . "' "
|
||||
. "AND doc.register_date <= '" . $date_to . "'"
|
||||
. "AND o.type=0 "
|
||||
. "ORDER BY doc.register_date, o.counter, o.product_code, o.product_name, doc.name ";
|
||||
$resultRows = $db->query($query);
|
||||
|
||||
$stockList = getStocksList();
|
||||
while ($row = $db->fetchByAssoc($resultRows)) {
|
||||
$data['doc'][$row['docid']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['ilosc'] += $row['oquantity'];
|
||||
$data['prod'][$row['oproduct_id']]['kod'] = $row['oproduct_code'];
|
||||
$data['prod'][$row['oproduct_id']]['nazwa'] = $row['oproduct_name'];
|
||||
$data['prod'][$row['oproduct_id']]['id'] = $row['oproduct_id'];
|
||||
$data['prod'][$row['oproduct_id']]['data'] = $row['docregister_date'];
|
||||
$data['prod'][$row['oproduct_id']]['numer'] = $row['docdocument_no'];
|
||||
$data['prod'][$row['oproduct_id']]['kartoteka'] = $row['docstockindex'];
|
||||
$data['prod'][$row['oproduct_id']]['jm'] = $app_list_strings['ecmproducts_unit_dom'][$row['punit_id']];
|
||||
$data['doc'][$row['docid']]['magazyn'] = $stockList[$row['docstock_id']];
|
||||
$data['doc'][$row['docid']]['magazynIn'] = $stockList[$row['docstock_in_id']];
|
||||
$data['doc'][$row['docid']]['nazwa'] = $row['docname'];
|
||||
$data['doc'][$row['docid']]['typ'] = $documentsList[$documentsSelected];
|
||||
$data['doc'][$row['docid']]['id'] = $row['docid'];
|
||||
$data['doc'][$row['docid']]['data'] = $row['docregister_date'];
|
||||
$data['doc'][$row['docid']]['numer'] = $row['docdocument_no'];
|
||||
$data['doc'][$row['docid']]['kartoteka'] = $row['docstockindex'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
function getDataPzWzFk($documentsSelected, $stockSelected, $date_from, $date_to, $accountId, $accountName) {
|
||||
//var_dump(!isset($documentsSelected) && !isset($stockSelected) && !isset($date_from) && !isset($date_to));
|
||||
if (!isset($documentsSelected) && !isset($stockSelected) && !isset($date_from) && !isset($date_to)) {
|
||||
return null;
|
||||
}
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
$documentsList = array(// dokumenty
|
||||
'EcmStockDocInsideOuts' => 'RW',
|
||||
'EcmStockDocInsideIns' => 'PW',
|
||||
'EcmStockDocMoves' => 'MM',
|
||||
'EcmStockDocCorrects' => 'KS',
|
||||
'EcmStockDocIns' => 'PZ',
|
||||
'EcmStockDocOuts' => 'WZ',
|
||||
'EcmInvoiceOuts' => "FK",
|
||||
'EcmReceipts' => 'Paragon'
|
||||
);
|
||||
|
||||
$query = "SELECT "
|
||||
. "doc.id AS docid, "
|
||||
. "doc.name AS docname, "
|
||||
. "DATE_FORMAT(doc.register_date,'%d.%m.%Y') AS docregister_date, "
|
||||
. "doc.document_no AS docdocument_no, "
|
||||
. "doc.stock_id AS docstock_id, "
|
||||
. "o.type AS otype, "
|
||||
. "o.quantity AS oquantity, "
|
||||
. "o.price AS oprice, "
|
||||
. "o.product_id AS oproduct_id, "
|
||||
. "o.product_name AS oproduct_name, "
|
||||
. "o.product_code as oproduct_code, "
|
||||
. "doc.parent_id as docparent_id, "
|
||||
. "doc.parent_name as docparent_name, ";
|
||||
if($documentsSelected == 'EcmStockDocOuts'){
|
||||
$query .= "doc.category as doccategory, ";
|
||||
}
|
||||
$query .= "p.unit_id as punit_id "
|
||||
. "FROM "
|
||||
. "ecmstockoperations o, "
|
||||
. "ecmproducts p, "
|
||||
. "" . strtolower($documentsSelected) . " doc "
|
||||
. "WHERE o.parent_id = doc.id "
|
||||
. "AND p.id = o.product_id "
|
||||
. "AND doc.deleted=0 "
|
||||
. "AND o.deleted=0 ";
|
||||
if($documentsSelected=='EcmInvoiceOuts'){
|
||||
$query .= " AND doc.canceled=0 ";
|
||||
}
|
||||
if (isset($accountId) && strlen($accountId) > 0) {
|
||||
$query .= "AND doc.parent_id='" . $accountId . "' ";
|
||||
}
|
||||
$query.= "AND doc.stock_id IN " . getStockQuery($stockSelected) . " "
|
||||
. "AND doc.register_date >='" . $date_from . "' "
|
||||
. "AND doc.register_date <= '" . $date_to . "'";
|
||||
|
||||
if($documentsSelected == 'EcmStockDocOuts' && $_REQUEST['wz_category'] != ""){
|
||||
$query.= " AND doc.category = '" . $_REQUEST['wz_category'] . "' ";
|
||||
}
|
||||
|
||||
$query .= " ORDER BY doc.register_date, o.counter, o.product_code, o.product_name, doc.name";
|
||||
$resultRows = $db->query($query);
|
||||
$stockList = getStocksList();
|
||||
while ($row = $db->fetchByAssoc($resultRows)) {
|
||||
|
||||
|
||||
$data['prod'][$row['oproduct_id']]['kod'] = $row['oproduct_code'];
|
||||
$data['prod'][$row['oproduct_id']]['nazwa'] = $row['oproduct_name'];
|
||||
$data['prod'][$row['oproduct_id']]['id'] = $row['oproduct_id'];
|
||||
$data['prod'][$row['oproduct_id']]['data'] = $row['docregister_date'];
|
||||
$data['prod'][$row['oproduct_id']]['otype'] = $row['otype'];
|
||||
$data['prod'][$row['oproduct_id']]['numer'] = $row['docdocument_no'];
|
||||
$data['prod'][$row['oproduct_id']]['jm'] = $app_list_strings['ecmproducts_unit_dom'][$row['punit_id']];
|
||||
$data['doc'][$row['docid']]['magazyn'] = $stockList[$row['docstock_id']];
|
||||
$data['doc'][$row['docid']]['accountId'] = $row['docparent_id'];
|
||||
$data['doc'][$row['docid']]['accountNazwa'] = $row['docparent_name'];
|
||||
$data['doc'][$row['docid']]['nazwa'] = $row['docname'];
|
||||
$data['doc'][$row['docid']]['typ'] = $documentsList[$documentsSelected];
|
||||
$data['doc'][$row['docid']]['id'] = $row['docid'];
|
||||
$data['doc'][$row['docid']]['doccategory'] = $app_list_strings['ecmstockdocouts_category_list'][$row['doccategory']];
|
||||
$data['doc'][$row['docid']]['data'] = $row['docregister_date'];
|
||||
$data['doc'][$row['docid']]['numer'] = $row['docdocument_no'];
|
||||
if ($documentsSelected == 'EcmInvoiceOuts' && $row['otype'] == '0') {
|
||||
$data['doc'][$row['docid']]['wartosc'] -= $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] -= $row['oquantity'] * $row['oprice'];
|
||||
$data['doc'][$row['docid']]['typ'] = 'KF';
|
||||
$data['prod'][$row['oproduct_id']]['ilosc'] -= $row['oquantity'];
|
||||
} else {
|
||||
$data['prod'][$row['oproduct_id']]['ilosc'] += $row['oquantity'];
|
||||
$data['doc'][$row['docid']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
$data['prod'][$row['oproduct_id']]['wartosc'] += $row['oquantity'] * $row['oprice'];
|
||||
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
//
|
||||
// ***************************************************************************
|
||||
//Pobieranie danych z filtrowania
|
||||
if ($_REQUEST['date_from'] == '') {
|
||||
$_REQUEST['date_from'] = date('01.m.Y');
|
||||
} else {
|
||||
$date_from = date('Y-m-d', strtotime($_REQUEST['date_from']));
|
||||
}
|
||||
if ($_REQUEST['date_to'] == '') {
|
||||
$_REQUEST['date_to'] = date('t.m.Y');
|
||||
} else {
|
||||
$date_to = date('Y-m-d', strtotime($_REQUEST['date_to']));
|
||||
}
|
||||
$stockSelected = $_REQUEST['stockSelected'];
|
||||
$documentsSelected = $_REQUEST['documentsSelected'];
|
||||
$stockIndexSelected = $_REQUEST['stockIndexSelected'];
|
||||
$viewSelected = $_REQUEST['viewSelected'];
|
||||
$mmSelected = $_REQUEST['mmSelected'];
|
||||
$accountId = $_REQUEST['accountId'];
|
||||
$accountName = $_REQUEST['accountName'];
|
||||
//Przygotowywanie innych potrzebnych zmiennych
|
||||
$data = array();
|
||||
$datatmp = array();
|
||||
$db = $GLOBALS['db'];
|
||||
global $mod_strings, $app_list_strings;
|
||||
$stockList = getStocksList(); // magazyny
|
||||
$stockIndexList = getStockIndexList(); //Kartoteki Materialowe
|
||||
$documentsList = array(// dokumenty
|
||||
'EcmStockDocInsideOuts' => 'RW',
|
||||
'EcmStockDocInsideIns' => 'PW',
|
||||
'EcmStockDocMoves' => 'MM',
|
||||
'EcmStockDocCorrects' => 'KS',
|
||||
'EcmStockDocIns' => 'PZ',
|
||||
'EcmStockDocOuts' => 'WZ',
|
||||
'EcmInvoiceOuts' => "FK",
|
||||
'EcmReceipts' => 'Paragon'
|
||||
);
|
||||
|
||||
$viewList = array(//Lista widokow
|
||||
'documents' => 'Dokumenty',
|
||||
'positions' => 'Pozycje',
|
||||
);
|
||||
|
||||
|
||||
//Pobieranie i przetwarzanie danych
|
||||
if ($documentsSelected == 'EcmStockDocInsideOuts' || $documentsSelected == 'EcmStockDocInsideIns' || $documentsSelected == 'EcmStockDocCorrects') {
|
||||
$data = getDataRwPwKs($documentsSelected, $stockSelected, $date_from, $date_to, $stockIndexSelected);
|
||||
} elseif ($documentsSelected == 'EcmStockDocMoves') {
|
||||
$data = getDataMm($documentsSelected, $stockSelected, $date_from, $date_to, $mmSelected);
|
||||
} elseif ($documentsSelected == 'EcmStockDocIns' || $documentsSelected == 'EcmStockDocOuts' || $documentsSelected == 'EcmInvoiceOuts' || $documentsSelected == 'EcmReceipts') {
|
||||
$data = getDataPzWzFk($documentsSelected, $stockSelected, $date_from, $date_to, $accountId, $accountName);
|
||||
}
|
||||
$kategorie_wz[""] = "";
|
||||
foreach($app_list_strings['ecmstockdocouts_category_list'] as $k => $v){
|
||||
$kategorie_wz[$k] = $v;
|
||||
}
|
||||
// create & execute smarty
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("APP_LIST_STRINGS", $app_list_strings);
|
||||
$smarty->assign("DATA", $data);
|
||||
$smarty->assign("kategorie_wz", $kategorie_wz);
|
||||
$smarty->assign("wz_category_selected", $_REQUEST['wz_category']);
|
||||
$smarty->assign("stocksList", $stockList);
|
||||
$smarty->assign("stockSelected", $stockSelected);
|
||||
$smarty->assign("documentList", $documentsList);
|
||||
$smarty->assign("documentSelected", $documentsSelected);
|
||||
$smarty->assign("stockIndexList", $stockIndexList);
|
||||
$smarty->assign("stockIndexSelected", $stockIndexSelected);
|
||||
$smarty->assign("viewList", $viewList);
|
||||
$smarty->assign("viewSelected", $viewSelected);
|
||||
$smarty->assign("date_from", $_REQUEST['date_from']);
|
||||
$smarty->assign("date_to", $_REQUEST['date_to']);
|
||||
$smarty->assign("aktualnaData", date("d.m.Y"));
|
||||
$smarty->assign("mmSelected", $mmSelected);
|
||||
$smarty->assign("accountId", $accountId);
|
||||
$smarty->assign("accountName", htmlentities($accountName));
|
||||
// Eksport do PDF
|
||||
if ($_REQUEST['toPDF'] == '1') {
|
||||
if ($_REQUEST['to_xls'] == '1') {
|
||||
|
||||
|
||||
$header=array();
|
||||
$header[]='numer dokumentu';
|
||||
$header[]='data';
|
||||
$header[]='kontrahent';
|
||||
$header[]='opis';
|
||||
$header[]='wartość';
|
||||
$header[]='magazyn';
|
||||
$filename='modules/Home/Files/obroty_wg_magazynu_'.date('d_m-Y').'.csv';
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
foreach ($data['doc'] as $key=>$val){
|
||||
$line=array();
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['typ'].' '.$val['numer']))).'"""';
|
||||
$line[]=$val['data'];
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['accountNazwa']))).'"""';
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['nazwa']))).'"""';
|
||||
|
||||
$line[]=str_replace(".",",",$val['wartosc']);
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['magazyn'])));
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
header("Location: ". $filename);
|
||||
} else {
|
||||
if ($documentsSelected == 'EcmStockDocInsideOuts' || $documentsSelected == 'EcmStockDocInsideIns' || $documentsSelected == 'EcmStockDocCorrects') {
|
||||
$txt = 'Kartoteka materiałowa: ';
|
||||
if (isset($stockIndexSelected)) {
|
||||
if (count($stockIndexSelected) == count($stockIndexList) + 1) {
|
||||
$txt .= 'Wszystkie';
|
||||
} else {
|
||||
foreach ($stockIndexSelected as $key => $value) {
|
||||
if ($value == 'NULL') {
|
||||
$txt .= 'Bez kartoteki materiałowej ,';
|
||||
} else {
|
||||
$txt .= $stockIndexList[$value] . ' ,';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$txt .= 'Wszystkie';
|
||||
}
|
||||
$txt = rtrim($txt, ",");
|
||||
} elseif ($documentsSelected == 'EcmStockDocMoves') {
|
||||
$txt = 'Do magazynu: ';
|
||||
if (isset($mmSelected)) {
|
||||
if (count($mmSelected) == count($stockList)) {
|
||||
$txt .= 'Wszystkie';
|
||||
} else {
|
||||
foreach ($mmSelected as $key => $value) {
|
||||
$txt .= $stockList[$value] . ' ,';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$txt .= 'Wszystkie';
|
||||
}
|
||||
$txt = rtrim($txt, ",");
|
||||
} elseif ($documentsSelected == 'EcmStockDocIns' || $documentsSelected == 'EcmStockDocOuts' || $documentsSelected == 'EcmInvoiceOuts' || $documentsSelected == 'EcmReceipts') {
|
||||
if (isset($accountName) && strlen($accountName) > 1) {
|
||||
$txt = 'Kontrahent: ' . $accountName;
|
||||
} else {
|
||||
$txt = 'Kontrahent: Wszyscy';
|
||||
}
|
||||
}
|
||||
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
$EcmSysInfo = new EcmSysInfo();
|
||||
$smarty->assign("nazwaFirmy", $EcmSysInfo->getName());
|
||||
$output = $smarty->fetch('modules/EcmReports/tpls/ReportStockDocMovesPDF.tpl');
|
||||
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
unset($smarty);
|
||||
|
||||
|
||||
$p = new mPDF('', 'A4', null, 'helvetica', 10, 10, 26, 10, 5, 5);
|
||||
$p->setFooter('{PAGENO}');
|
||||
$p->setHTMLHeader('<div style="text-align: left; border-bottom: 1px solid #000000; font-weight: bold; font-size: 10pt;">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="font-weight: bold; font-size: 9pt;">Obroty wg dokumentów ' . $documentsList[$documentsSelected] . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold; font-size: 9pt;">' . $EcmSysInfo->getName() . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold; font-size: 9pt;">Data wygenerowania: ' . date("d.m.Y") . ' Okres: ' . $_REQUEST['date_from'] . ' do ' . $_REQUEST['date_to'] . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="font-weight: bold; font-size: 9pt;">' . $txt . ' </td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>');
|
||||
|
||||
$p->writeHTML($output);
|
||||
$p->Output("ObrotWgDokumentow_" . $documentsList[$documentsSelected] . "_" . $_REQUEST['date_from'] . "-" . $_REQUEST['date_to'].".pdf", "I");
|
||||
}
|
||||
} else {
|
||||
$smarty->display('modules/EcmReports/tpls/ReportStockDocMoves.tpl');
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
// partie
|
||||
include 'EcmConfig.php';
|
||||
|
||||
ini_set('memory_limit', '-1');
|
||||
ini_set('max_execution_time', '-1');
|
||||
if (!defined('sugarEntry') || !sugarEntry)
|
||||
die('Not A Valid Entry Point');
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
global $app_list_strings;
|
||||
$doc_name = array(
|
||||
'EcmStockDocInsideIns' => 'PW',
|
||||
'EcmStockDocMoves' => 'MM',
|
||||
'EcmStockDocCorrects' => 'KS',
|
||||
'EcmStockDocIns' => 'PZ'
|
||||
);
|
||||
/*
|
||||
* Magazyny
|
||||
*/
|
||||
$datastocks = array();
|
||||
$users = array();
|
||||
$queryStocks = "SELECT
|
||||
name,
|
||||
id
|
||||
FROM ecmstocks
|
||||
where deleted= 0";
|
||||
$rowsStocks = $db->query($queryStocks);
|
||||
$s = array();
|
||||
while ($rowStocks = $db->fetchByAssoc($rowsStocks)) {
|
||||
$stocks["name"] = $rowStocks["name"];
|
||||
$stocks["id"] = $rowStocks["id"];
|
||||
$datastocks[] = $stocks;
|
||||
$s[$stocks["id"]]['name'] = $stocks["name"];
|
||||
}
|
||||
if ($_GET['date_from'] == '') {
|
||||
$_GET['date_from'] = date('01.m.Y');
|
||||
} else {
|
||||
$date_from = date('Y-m-d 00:00:01', strtotime($_GET['date_from']));
|
||||
}
|
||||
if ($_GET['date_to'] == '') {
|
||||
$_GET['date_to'] = date('t.m.Y');
|
||||
} else {
|
||||
$date_to = date('Y-m-d 23:59:59', strtotime($_GET['date_to']));
|
||||
}
|
||||
|
||||
/*
|
||||
* Dodatkowe parametry do zapytania
|
||||
*/
|
||||
if ($_GET['selectStock'] != "")
|
||||
$add_where .= " and stock_id = '" . $_GET["selectStock"] . "' ";
|
||||
|
||||
if ($_GET['selectProductActive'] != "") {
|
||||
$where = " WHERE product_active = '" . $_GET["selectProductActive"] . "' ";
|
||||
} else {
|
||||
$where = '';
|
||||
}
|
||||
$_GET['selectShowEmpty'] = 1;
|
||||
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts " . $where . " order by name asc");
|
||||
$docs = array();
|
||||
$i = 0;
|
||||
$skip = array();
|
||||
$total_quantity_old = 0;
|
||||
$total_value_old = 0;
|
||||
|
||||
if($_GET['submit']=='Wykonaj'){
|
||||
|
||||
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query("select * from ecmstockoperations where
|
||||
product_id='" . $tmp2['id'] . "'
|
||||
" . $add_where . "
|
||||
and in_id is null and type=0 and date_entered <='" . $date_from . "'");
|
||||
|
||||
$l = 0;
|
||||
$i = $tmp2['id'];
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id'] = $app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id'] = $tmp2['id'];
|
||||
$docs[$i]['product_name'] = $tmp2['name'];
|
||||
$docs[$i]['product_code'] = $tmp2['code'];
|
||||
$docs[$i]['total_quantity_old'] = 0;
|
||||
$docs[$i]['total_price_old'] = 0;
|
||||
|
||||
} else {
|
||||
$skip[$tmp2['id']]['start'] = 1;
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
|
||||
$ii = $db->query("select * from ecmstockoperations where in_id='" . $tmp['id'] . "' and type=1 and date_entered <='" . $date_from . "'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
|
||||
$quantity_tmp -= $tmp2['quantity'];
|
||||
}
|
||||
if ($quantity_tmp == 0) {
|
||||
$db->query("update ecmstockoperations set used=1 where id='" . $tmp['id'] . "'");
|
||||
continue;
|
||||
}
|
||||
$doc['quantity'] = $quantity_tmp;
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_type2'] = $tmp['parent_type'];
|
||||
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['position_value'] = $doc['quantity'] * $tmp['price'];
|
||||
$total_quantity_old += $doc['quantity'];
|
||||
$total_value_old += round($doc['quantity'] * $tmp['price'], 2);
|
||||
//$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_old'] += ($doc['quantity'] * $tmp['price']);
|
||||
$docs[$i]['total_quantity_old'] += ($doc['quantity']);
|
||||
} else {
|
||||
|
||||
// dla całych
|
||||
$doc['quantity'] = $tmp['quantity'];
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
$doc['position_value'] = $doc['quantity'] * $tmp['price'];
|
||||
$total_quantity_old += $doc['quantity'];
|
||||
$total_value_old += round($doc['quantity'] * $tmp['price'], 2);
|
||||
// $docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_old'] += ($doc['quantity'] * $tmp['price']);
|
||||
|
||||
$docs[$i]['total_quantity_old'] += ($doc['quantity']);
|
||||
|
||||
}
|
||||
|
||||
if ($r->num_rows > 1) {
|
||||
$docs[$i]['price'] = $docs[$i]['total_price_old'] / $docs[$i]['total_quantity_old'];
|
||||
$docs[$i]['parent_name'] = '';
|
||||
$docs[$i]['parent_type'] = '';
|
||||
}
|
||||
if ($r->num_rows < 2) {
|
||||
$docs[$i]['price'] = $tmp['price'];
|
||||
|
||||
$doc[$i]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i]['parent_id'] = $tmp['parent_id'];
|
||||
$docs[$i]['parent_name'] = $tmp['parent_name'];
|
||||
// $docs[$i-1]['date_entered'] = $n->register_date;
|
||||
$docs[$i]['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
} else {
|
||||
$docs[$i]['price'] = $docs[$i]['total_price_old'] / $docs[$i]['total_quantity_old'];
|
||||
$docs[$i]['parent_name'] = '';
|
||||
$docs[$i]['parent_type'] = '';
|
||||
}
|
||||
|
||||
}
|
||||
//if( $docs[$i]['total_quantity_old']==0 && $_GET['selectShowEmpty']!='')unset($docs[$i]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts " . $where . " order by name asc");
|
||||
|
||||
$i = 0;
|
||||
$total_quantity_now = 0;
|
||||
$total_value_now = 0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query("select * from ecmstockoperations where
|
||||
product_id='" . $tmp2['id'] . "'
|
||||
" . $add_where . "
|
||||
and in_id is null and type=0 and date_entered <'" . $date_to . "'");
|
||||
$i = $tmp2['id'];
|
||||
$l = 0;
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id'] = $app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id'] = $tmp2['id'];
|
||||
$docs[$i]['product_name'] = $tmp2['name'];
|
||||
$docs[$i]['product_code'] = $tmp2['code'];
|
||||
$docs[$i]['total_quantity_now'] = 0;
|
||||
$docs[$i]['total_price_now'] = 0;
|
||||
|
||||
} else {
|
||||
$skip[$tmp2['id']]['mid'] = 1;
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
|
||||
$ii = $db->query("select * from ecmstockoperations where in_id='" . $tmp['id'] . "' and type=1 and date_entered <'" . $date_to . "'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
|
||||
$quantity_tmp -= $tmp2['quantity'];
|
||||
}
|
||||
if ($quantity_tmp == 0) {
|
||||
$db->query("update ecmstockoperations set used=1 where id='" . $tmp['id'] . "'");
|
||||
continue;
|
||||
}
|
||||
|
||||
$doc['quantity'] = $quantity_tmp;
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_type2'] = $tmp['parent_type'];
|
||||
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['position_value'] = $doc['quantity'] * $tmp['price'];
|
||||
$total_quantity_now += $doc['quantity'];
|
||||
$total_value_now += round($doc['quantity'] * $tmp['price'], 2);
|
||||
//$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_now'] += ($doc['quantity'] * $tmp['price']);
|
||||
$docs[$i]['total_quantity_now'] += ($doc['quantity']);
|
||||
} else {
|
||||
// dla całych
|
||||
$doc['quantity'] = $tmp['quantity'];
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
|
||||
// $doc['date_entered'] = $n->register_date;
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
$doc['position_value'] = $doc['quantity'] * $tmp['price'];
|
||||
$total_quantity_now += $doc['quantity'];
|
||||
$total_value_now += round($doc['quantity'] * $tmp['price'], 2);
|
||||
// $docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i]['total_price_now'] += ($doc['quantity'] * $tmp['price']);
|
||||
$docs[$i]['total_quantity_now'] += ($doc['quantity']);
|
||||
|
||||
}
|
||||
|
||||
if ($r->num_rows > 1) {
|
||||
$docs[$i]['price'] = $docs[$i]['total_price_now'] / $docs[$i]['total_quantity_now'];
|
||||
$docs[$i]['parent_name'] = '';
|
||||
$docs[$i]['parent_type'] = '';
|
||||
}
|
||||
if ($r->num_rows < 2) {
|
||||
$docs[$i]['price'] = $tmp['price'];
|
||||
|
||||
$doc[$i]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i]['parent_id'] = $tmp['parent_id'];
|
||||
$docs[$i]['parent_name'] = $tmp['parent_name'];
|
||||
// $docs[$i-1]['date_entered'] = $n->register_date;
|
||||
$docs[$i]['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
} else {
|
||||
$docs[$i]['price'] = $docs[$i]['total_price_now'] / $docs[$i]['total_quantity_now'];
|
||||
$docs[$i]['parent_name'] = '';
|
||||
$docs[$i]['parent_type'] = '';
|
||||
}
|
||||
|
||||
}
|
||||
// if( $docs[$i]['total_quantity_now']==0 && $_GET['selectShowEmpty']!='')unset($docs[$i]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts " . $where . " order by name asc");
|
||||
|
||||
$i = 0;
|
||||
$przychod_w = 0;
|
||||
$przychod_q = 0;
|
||||
$rozchod_q = 0;
|
||||
$rozchod_w = 0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query("select * from ecmstockoperations where
|
||||
product_id='" . $tmp2['id'] . "'
|
||||
" . $add_where . "
|
||||
and in_id is null and type=0 and date_entered <'" . $date_to . "' and date_entered >='" . $date_from . "'");
|
||||
$i = $tmp2['id'];
|
||||
$l = 0;
|
||||
if ($r->num_rows > 0) {
|
||||
|
||||
$docs[$i]['rozchod_q'] = 0;
|
||||
$docs[$i]['rozchod_w'] = 0;
|
||||
$docs[$i]['przychod_q'] = 0;
|
||||
$docs[$i]['przychod_w'] = 0;
|
||||
} else {
|
||||
$skip[$tmp2['id']]['end'] = 1;
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
$module=substr($tmp['parent_type'], 0, -1);
|
||||
|
||||
$doc = new $module();
|
||||
$doc->retrieve($tmp['parent_id']);
|
||||
if($doc->type=='correct'){
|
||||
$docs[$i]['rozchod_w'] += (-1*$tmp['quantity'] * $tmp['price']);
|
||||
$docs[$i]['rozchod_q'] += ($tmp['quantity']*-1);
|
||||
$rozchod_w += ($tmp['quantity'] * $tmp['price']*-1);
|
||||
$rozchod_q += ($tmp['quantity']*-1);
|
||||
} else {
|
||||
$docs[$i]['przychod_w'] += ($tmp['quantity'] * $tmp['price']);
|
||||
$docs[$i]['przychod_q'] += ($tmp['quantity']);
|
||||
$przychod_w += ($tmp['quantity'] * $tmp['price']);
|
||||
;
|
||||
$przychod_q += ($tmp['quantity']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$ii = $db->query("select * from ecmstockoperations where product_id='" . $tmp2['id'] . "' and type=1 and date_entered <'" . $date_to . "' " . $add_where . " and date_entered >='" . $date_from . "'");
|
||||
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp3 = $db->fetchByAssoc($ii)) {
|
||||
$docs[$i]['rozchod_w'] += ($tmp3['quantity'] * $tmp3['price']);
|
||||
$docs[$i]['rozchod_q'] += ($tmp3['quantity']);
|
||||
$rozchod_w += ($tmp3['quantity'] * $tmp3['price']);
|
||||
$rozchod_q += ($tmp3['quantity']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$docs[$i]['unit_id'] = $app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['unit_precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id'] = $tmp2['id'];
|
||||
$docs[$i]['product_name'] = $tmp2['name'];
|
||||
$docs[$i]['product_code'] = $tmp2['code'];
|
||||
}
|
||||
foreach ($skip as $key => $id) {
|
||||
if ($skip[$key]['end'] == 1 && $skip[$key]['mid'] == 1 && $skip[$key]['start'] == 1) {
|
||||
unset($docs[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// create & execute smarty
|
||||
$smarty = new Sugar_Smarty();
|
||||
global $mod_strings;
|
||||
$smarty->assign("MOD", $mod_strings);
|
||||
$smarty->assign("DATA", $docs);
|
||||
$smarty->assign("date_from", $_GET['date_from']);
|
||||
$smarty->assign("date_to", $_GET['date_to']);
|
||||
$smarty->assign("TOTAL_VALUE_OLD", $total_value_old);
|
||||
$smarty->assign("TOTAL_QUANTITY_OLD", $total_quantity_old);
|
||||
$smarty->assign("TOTAL_VALUE_NOW", $total_value_now);
|
||||
$smarty->assign("TOTAL_QUANTITY_NOW", $total_quantity_now);
|
||||
$smarty->assign("rozchod_w", $rozchod_w);
|
||||
$smarty->assign("rozchod_q", $rozchod_q);
|
||||
$smarty->assign("przychod_w", $przychod_w);
|
||||
$smarty->assign("przychod_q", $przychod_q);
|
||||
$smarty->assign("CONSIGNMENTS", $EcmConfig['consignments']);
|
||||
$smarty->assign("STOCKS", $datastocks);
|
||||
$smarty->assign("selectStock", $_GET["selectStock"]);
|
||||
$smarty->assign("selectProductActive", $_GET["selectProductActive"]);
|
||||
$smarty->assign("selectProductEol", $_GET["selectProductEol"]);
|
||||
$smarty->assign("selectShowEmpty", $_GET["selectShowEmpty"]);
|
||||
|
||||
|
||||
// Eksport do PDF
|
||||
if ($_GET['toPDF'] == '1') {
|
||||
|
||||
$output = $smarty->fetch('modules/EcmReports/tpls/PDF/ReportStockNewDoc.tpl');
|
||||
|
||||
include_once("include/MPDF57/mpdf.php");
|
||||
unset($smarty);
|
||||
if( $_GET ["selectStock"]!=''){
|
||||
$s = new EcmStock();
|
||||
$s->retrieve($_GET ["selectStock"]);
|
||||
$magazyn_nazwa = $s->name;
|
||||
}else{
|
||||
$magazyn_nazwa = 'Wszystkie';
|
||||
}
|
||||
$p = new mPDF('', 'A4', null, 'helvetica', 5, 5, 23, 5, 5, 5);
|
||||
$p->setFooter('Strona {PAGENO} z {nbpg}');
|
||||
$EcmSysInfos = new EcmSysInfo();
|
||||
$p->SetHTMLHeader('<p style="text-align:left;font-size: 10px;">' . $EcmSysInfos->getName() . '<br>
|
||||
Raport magazynowy - Stany magazynowe za okres ' . $_GET['date_from'] . ' - ' . $_GET['date_to'] . '<br>Data wydruku: ' . date("d.m.Y") . '<br>Magazyn: ' . $magazyn_nazwa . '</p>');
|
||||
//$p->setTitle($mod_strings["LBL_REPORT_STOCKS_DOCS"]);
|
||||
//echo $output;
|
||||
|
||||
$p->writeHTML($output);
|
||||
|
||||
$p->Output();
|
||||
} else {
|
||||
$smarty->display('modules/EcmReports/tpls/ReportStockNewDoc.tpl');
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
global $mod_strings, $app_list_strings, $db;
|
||||
// partie
|
||||
$EcmConfig = array (
|
||||
'consignments' => true,
|
||||
'consignments_label1' => 'Nr',
|
||||
);
|
||||
ini_set('memory_limit','-1');
|
||||
ini_set('max_execution_time','-1');
|
||||
|
||||
|
||||
|
||||
$doc_name=array('EcmStockDocInsideIns'=>'PW','EcmStockDocMoves'=>'MM','EcmStockDocCorrects'=>'KS','EcmStockDocIns'=>'PZ');
|
||||
/*
|
||||
* Magazyny
|
||||
*/
|
||||
$datastocks = array ();
|
||||
$users = array ();
|
||||
$queryStocks = "SELECT
|
||||
name,
|
||||
id
|
||||
FROM ecmstocks
|
||||
where deleted= 0";
|
||||
$rowsStocks = $db->query ( $queryStocks );
|
||||
|
||||
while ( $rowStocks = $db->fetchByAssoc ( $rowsStocks ) ) {
|
||||
$stocks ["name"] = $rowStocks ["name"];
|
||||
$stocks ["id"] = $rowStocks ["id"];
|
||||
$datastocks [] = $stocks;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dodatkowe parametry do zapytania
|
||||
*/
|
||||
if ($_GET ['selectStock'] != "")
|
||||
$add_where .= " and stock_id = '" . $_GET ["selectStock"] . "' ";
|
||||
|
||||
if ($_GET ['selectProductActive'] != ""){
|
||||
$where= " WHERE product_active = '" . $_GET ["selectProductActive"] . "' ";
|
||||
} else {
|
||||
$where='';
|
||||
}
|
||||
$_GET['selectShowEmpty']=1;
|
||||
$r1 = $db->query("select id,name,code,unit_id from ecmproducts ".$where." order by name asc");
|
||||
$docs = array();
|
||||
$i=0;
|
||||
$total_quantity=0;
|
||||
$total_value=0;
|
||||
while ($tmp2 = $db->fetchByAssoc($r1)) {
|
||||
$r = $db->query("select * from ecmstockoperations where product_id='" . $tmp2['id'] . "' ".$add_where." and in_id is null and used=0 and type=0 order by counter asc");
|
||||
$l = 0;
|
||||
if ($r->num_rows > 0) {
|
||||
$docs[$i]['unit_id'] = $app_list_strings['ecmproducts_unit_dom'][$tmp2['unit_id']];
|
||||
$docs[$i]['unit_precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$tmp2['unit_id']];
|
||||
$docs[$i]['product_id'] = $tmp2['id'];
|
||||
$docs[$i]['product_name'] = $tmp2['name'];
|
||||
$docs[$i]['product_code'] = $tmp2['code'];
|
||||
$docs[$i]['total_quantity'] = 0;
|
||||
$docs[$i]['total_price'] = 0;
|
||||
$i++;
|
||||
}
|
||||
while ($tmp = $db->fetchByAssoc($r)) {
|
||||
|
||||
$ii = $db->query( "select * from ecmstockoperations where in_id='" . $tmp['id'] ."' and type=1");
|
||||
if ($ii->num_rows > 0) {
|
||||
// licz ilość dla użytych
|
||||
$quantity_tmp = $tmp['quantity'];
|
||||
while ($tmp2 = $db->fetchByAssoc($ii)) {
|
||||
$quantity_tmp -= $tmp2['quantity'];
|
||||
}
|
||||
if($quantity_tmp==0){
|
||||
$db->query("update ecmstockoperations set used=1 where id='".$tmp['id']."'");
|
||||
continue;
|
||||
}
|
||||
$doc['quantity'] = $quantity_tmp;
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_type2'] = $tmp['parent_type'];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['product_id'] = $tmp['id'];
|
||||
$doc['date_entered'] = $tmp['date_entered'];
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity+=$doc['quantity'];
|
||||
$total_value+=round($doc['quantity']*$tmp['price'],2);
|
||||
$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i-1]['total_price']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i-1]['part_no'] =$tmp['part_no'];
|
||||
$docs[$i-1]['total_quantity']+=($doc['quantity']);
|
||||
} else {
|
||||
// dla całych
|
||||
$doc['quantity'] = $tmp['quantity'];
|
||||
$doc['parent_name'] = $tmp['parent_name'];
|
||||
$doc['price'] = $tmp['price'];
|
||||
$doc['part_no'] = $tmp['part_no'];
|
||||
$doc['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
$doc['parent_id'] = $tmp['parent_id'];
|
||||
$doc['date_entered'] = $tmp['date_entered'];
|
||||
$doc['product_id'] = $tmp2['id'];
|
||||
$doc['position_value'] = $doc['quantity']*$tmp['price'];
|
||||
$total_quantity+=$doc['quantity'];
|
||||
$total_value+=round($doc['quantity']*$tmp['price'],2);
|
||||
$docs[$i-1]['add'][] = $doc;
|
||||
$docs[$i-1]['total_price']+=($doc['quantity']*$tmp['price'] );
|
||||
$docs[$i-1]['total_quantity']+=($doc['quantity']);
|
||||
$docs[$i-1]['part_no'] =$tmp['part_no'];
|
||||
|
||||
}
|
||||
if ($r->num_rows > 1) {
|
||||
$docs[$i-1]['price']='';
|
||||
$docs[$i-1]['parent_name']='';
|
||||
$doc[$i-1]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i-1]['parent_type']='';
|
||||
} if ($r->num_rows < 2 ){
|
||||
$docs[$i-1]['price']=$tmp['price'];
|
||||
$doc[$i-1]['part_no'] = $tmp['part_no'];
|
||||
$docs[$i-1]['parent_id'] = $tmp['parent_id'];
|
||||
$docs[$i-1]['parent_name']=$tmp['parent_name'];
|
||||
$docs[$i-1]['date_entered'] = $tmp['date_entered'];
|
||||
$docs[$i-1]['parent_type'] = $doc_name[$tmp['parent_type']];
|
||||
}else {
|
||||
$docs[$i-1]['price']='';
|
||||
$docs[$i-1]['parent_name']='';
|
||||
$docs[$i-1]['parent_type']='';
|
||||
}
|
||||
|
||||
}
|
||||
if( $docs[$i-1]['total_quantity']==0 && $_GET['selectShowEmpty']!='')unset($docs[$i-1]);
|
||||
}
|
||||
// create & execute smarty
|
||||
$smarty = new Sugar_Smarty ();
|
||||
global $mod_strings;
|
||||
$smarty->assign ( "MOD", $mod_strings );
|
||||
$smarty->assign ( "DATA", $docs );
|
||||
$smarty->assign ( "TOTAL_VALUE", $total_value );
|
||||
$smarty->assign ( "TOTAL_QUANTITY", $total_quantity );
|
||||
$smarty->assign ( "CONSIGNMENTS",$EcmConfig['consignments']);
|
||||
$smarty->assign ( "STOCKS", $datastocks );
|
||||
if($_REQUEST['data']=='')$_REQUEST['data'] =date('d.m.Y');
|
||||
$smarty->assign ( "date", $_REQUEST['data'] );
|
||||
$smarty->assign ( "selectStock", $_GET ["selectStock"]);
|
||||
$smarty->assign ( "selectProductActive", $_GET ["selectProductActive"] );
|
||||
$smarty->assign ( "selectProductEol", $_GET ["selectProductEol"] );
|
||||
$smarty->assign ( "selectShowEmpty", $_GET ["selectShowEmpty"] );
|
||||
|
||||
// Eksport do PDF
|
||||
if( $_GET['toPDF'] == '1' ) {
|
||||
if( $_GET['to_xls'] == '1' ) {
|
||||
|
||||
$header=array();
|
||||
$header[]='indeks';
|
||||
$header[]='nazwa';
|
||||
$header[]='dokument';
|
||||
$header[]='ilosc';
|
||||
$header[]='cena';
|
||||
$header[]='suma';
|
||||
$filename='modules/Home/Files/raport_stanow_magazynowych_'.date('d_m-Y').'.csv';
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
foreach ($docs as $key=>$val){
|
||||
$line=array();
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['product_code']))).'"""';
|
||||
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['product_name']))).'"""';
|
||||
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['parent_type'].' '.$val['parent_name']))).'"""';
|
||||
|
||||
|
||||
$line[]=str_replace(".",",",$val['total_quantity']);
|
||||
$line[]=str_replace(".",",",$val['price']);
|
||||
$line[]=str_replace(".",",",$val['total_price']);
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
if(count($val['add'])>1){
|
||||
|
||||
foreach($val['add'] as $k2=>$v2){
|
||||
$line=array();
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['product_code']))).'"""';
|
||||
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['product_name']))).'"""';
|
||||
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['parent_type'].' '.$v2['parent_name']))).'"""';
|
||||
|
||||
$line[]=str_replace(".",",",$v2['quantity']);
|
||||
$line[]=str_replace(".",",",$v2['price']);
|
||||
$line[]=str_replace(".",",",$v2['position_price']);
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
header("Location: ". $filename);
|
||||
} else {
|
||||
$output = $smarty->fetch( 'modules/EcmReports/tpls/PDF/ReportStocksDoc.tpl' );
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
unset($smarty);
|
||||
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 25, 10, 5, 5 );
|
||||
$p->setFooter('Strona {PAGENO} z {nbpg}');
|
||||
if( $_GET ["selectStock"]!=''){
|
||||
$s = new EcmStock();
|
||||
$s->retrieve($_GET ["selectStock"]);
|
||||
$dopisek = $s->name;
|
||||
}else{
|
||||
$dopisek = 'Wszystkie';
|
||||
}
|
||||
$EcmSysInfos = new EcmSysInfo();
|
||||
$p->SetHTMLHeader('<p style="text-align:left;font-size: 10px;">' . $EcmSysInfos->getName() . '<br>
|
||||
Raport Magazynowy - Stany magazynowe<br>Data wydruku: '.date("d.m.Y",strtotime($_REQUEST['data'])).'<br>Magazyn: ' . $dopisek .'</p>');
|
||||
//$p->setTitle($mod_strings["LBL_REPORT_STOCKS_DOCS"]);
|
||||
//echo $output;
|
||||
$p->writeHTML( $output );
|
||||
|
||||
$p->Output ();
|
||||
}
|
||||
} else {
|
||||
$smarty->display ( 'modules/EcmReports/tpls/ReportStocksDoc.tpl' );
|
||||
}
|
||||
?>
|
||||
240
modules/var/www/html/system/modules/EcmReports/ReportValue.php
Normal file
240
modules/var/www/html/system/modules/EcmReports/ReportValue.php
Normal file
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
||||
die ( 'Not A Valid Entry Point' );
|
||||
/**
|
||||
* ********************* PREPARE ********************
|
||||
*/
|
||||
|
||||
global $app_list_strings;
|
||||
global $current_user;
|
||||
$db = $GLOBALS ['db'];
|
||||
$data = array ();
|
||||
$date_from = date("Y-01-01");
|
||||
$date_to = date("Y-m-01");
|
||||
$query = "";
|
||||
$selectedColumns = array();
|
||||
$suma = array();
|
||||
$mons = array( 1 => "Styczeń",
|
||||
2 => "Luty",
|
||||
3 => "Marzec",
|
||||
4 => "Kwiecień",
|
||||
5 => "Maj",
|
||||
6 => "Czerwiec",
|
||||
7 => "Lipiec",
|
||||
8 => "Sierpień",
|
||||
9 => "Wrzesień",
|
||||
10 => "Październik",
|
||||
11 => "Listopad",
|
||||
12 => "Grudzień");
|
||||
// Pobieranie danych z formularza
|
||||
if(!$_GET['date_from']){
|
||||
$date_from = date("Y-01-01");
|
||||
}else{
|
||||
$date_from = $_GET['date_from'];
|
||||
$tmp = date_parse_from_format("d.m.Y", $_GET['date_from']);
|
||||
$date_from = date($tmp['year']."-".$tmp['month']."-01");
|
||||
}
|
||||
if(!$_GET['date_to']){
|
||||
$date_to = date("Y-m-d");
|
||||
}else{
|
||||
$date_to = $_GET['date_to'];
|
||||
}
|
||||
//formatowanie daty
|
||||
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
|
||||
$date_from = $GLOBALS['timedate']->to_display_date($date_from);
|
||||
$date_to = $GLOBALS['timedate']->to_display_date($date_to);
|
||||
|
||||
$selectedColumns = json_decode($current_user->getPreference('ecmreports_reportvalue_column'));
|
||||
//Sprawdzanie jakie kolumny ma zaznaczone uzytkownik i zapisywanie do bazy w razie zmian
|
||||
|
||||
if($_GET['selectedColumns']==NULL){
|
||||
//Jeśli nic nie bylo przeslane z formularza i nie bylo nic w bazie
|
||||
//tworzy nowa tablice z zaznaczonymi wszystkimi kolumnami
|
||||
if($selectedColumns==NULL){
|
||||
$selectedColumns = array();
|
||||
foreach($app_list_strings['document_category_dom'] as $key=> $value){
|
||||
$selectedColumns[] = $key;
|
||||
}
|
||||
// i ja zapisuje
|
||||
$current_user->setPreference('ecmreports_reportvalue_column', json_encode($selectedColumns));
|
||||
}
|
||||
}else{
|
||||
// Jeśli było coś przesłane przez formularz i nie bylo nic w bazie
|
||||
// to zapisuje przeslane kolumny
|
||||
if($selectedColumns==NULL){
|
||||
$current_user->setPreference('ecmreports_reportvalue_column', json_encode($_GET['selectedColumns']));
|
||||
}else{
|
||||
// Jesli bylo cos przeslane przez formularz i bylo cos w bazie
|
||||
// sprawdza czy tablice sie roznia elementami - jak tak to zapisuje zmiany do bazy
|
||||
// i ustawia nowe kolumny
|
||||
if(count($_GET['selectedColumns'])!=count($selectedColumns)){
|
||||
if(count($_GET['selectedColumns'])!=0){
|
||||
$current_user->setPreference('ecmreports_reportvalue_column', json_encode($_GET['selectedColumns']));
|
||||
$selectedColumns = $_GET['selectedColumns'];
|
||||
}
|
||||
}
|
||||
// Jak nic sie nie zmienilo to nic nie robi bo po co
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ************* GET DATA FROM DB********************
|
||||
*/
|
||||
|
||||
//Wybieranie zaznaczonych kolumn
|
||||
$querycategory="";
|
||||
foreach($selectedColumns as $value){
|
||||
$querycategory = $querycategory . "'" . $value ."',";
|
||||
}
|
||||
$querycategory = rtrim($querycategory, ',');
|
||||
$tmp = date_parse_from_format("d.m.Y", $date_to);
|
||||
$date_finish_m = $tmp['month'];
|
||||
$date_finish_y = $tmp['year'];
|
||||
$date_finish_d = $tmp['day'];
|
||||
|
||||
$tmp = date_parse_from_format("d.m.Y", $date_from);
|
||||
$date_f_month = $tmp['month']-1;
|
||||
$date_f_year = $tmp['year'];
|
||||
$date_f = "01.". $date_f_month . "." . $date_f_year;
|
||||
$date_t_year = $date_f_year;
|
||||
$data[$date_f_year] = array();
|
||||
do{
|
||||
$date_f_month++;
|
||||
if($date_f_month == 13){
|
||||
$date_f_month = 1;
|
||||
$date_f_year++;
|
||||
$data[$date_f_year] = array();
|
||||
}
|
||||
$date_f = "01.". $date_f_month . "." . $date_f_year;
|
||||
|
||||
$date_t_month = $date_f_month + 1;
|
||||
if($date_t_month == 13){
|
||||
$date_t_month = 1;
|
||||
$date_t_year++;
|
||||
}
|
||||
if($date_f_year == $date_finish_y && $date_f_month == $date_finish_m){
|
||||
$date_t_month = $date_finish_m;
|
||||
$date_t_year = $date_finish_y;
|
||||
$date_t_day = $date_finish_d;
|
||||
}else{
|
||||
$date_t_day = "01";
|
||||
}
|
||||
$date_t = $date_t_day .".". $date_t_month . "." . $date_t_year;
|
||||
// inicjalizacja danych
|
||||
|
||||
|
||||
$querydatefrom = "STR_TO_DATE('".$date_f."','%d.%m.%Y') ";
|
||||
$querydateto = "STR_TO_DATE('".$date_t."','%d.%m.%Y') ";
|
||||
$query = "SELECT
|
||||
category_id,
|
||||
ROUND(SUM(ifnull(value,'0,00')),2) as value
|
||||
FROM
|
||||
documents
|
||||
WHERE
|
||||
deleted=0 AND
|
||||
category_id IN (".$querycategory.") AND
|
||||
date_entered >= " . $querydatefrom . " AND
|
||||
date_entered <= " . $querydateto . "
|
||||
group by category_id";
|
||||
$rows = $db->query ( $query );
|
||||
$data[$date_f_year][$mons[$date_f_month]] = array();
|
||||
if($rows->num_rows == 0){
|
||||
// Jeśli baza nie zwróci żadnych rekordów to ustawia puste pola
|
||||
foreach($selectedColumns as $wartosc){
|
||||
$data[$date_f_year][$mons[$date_f_month]][] = '0,00';
|
||||
}
|
||||
// Dodatkowa kolumna na sumę
|
||||
$data[$date_f_year][$mons[$date_f_month]][] = '0,00';
|
||||
}else{
|
||||
$tmp2 = array();
|
||||
$sumka = 0;
|
||||
// Rekordy z bazy danych wpisujemy do tymczasowej tabeli by móc wstawić dane w odpowiednie miejsce
|
||||
while ( $r = $db->fetchByAssoc ( $rows ) ) {
|
||||
$row = array ();
|
||||
$row['category_id'] = $r['category_id'];
|
||||
$row['value'] = number_format($r['value'], 2, ",", ".");
|
||||
$sumka +=$r['value'];
|
||||
$tmp2[] = $row;
|
||||
}
|
||||
// tutaj wstawiamy w odpowiednie miejsce
|
||||
foreach($selectedColumns as $wartosc){
|
||||
$sprawdzamy = false;
|
||||
foreach($tmp2 as $cos){
|
||||
if($wartosc==$cos['category_id']){
|
||||
$sprawdzamy = true;
|
||||
$data[$date_f_year][$mons[$date_f_month]][] = $cos['value'];
|
||||
}
|
||||
}
|
||||
if(!$sprawdzamy){
|
||||
$data[$date_f_year][$mons[$date_f_month]][] = '0,00';
|
||||
}
|
||||
}
|
||||
// dodajemy ostatni wiersz sumy
|
||||
$data[$date_f_year][$mons[$date_f_month]][]=number_format($sumka, 2, ",", ".");
|
||||
}
|
||||
}while(!($date_f_year == $date_finish_y && $date_f_month == $date_finish_m && $date_t_day == $date_finish_d));
|
||||
|
||||
//Pobieranie sumy dla każdego typu
|
||||
$query = "SELECT
|
||||
category_id,
|
||||
ROUND(SUM(ifnull(value,'0,00')),2) as value
|
||||
FROM
|
||||
documents
|
||||
WHERE
|
||||
deleted=0 AND
|
||||
category_id IN (".$querycategory.") AND
|
||||
date_entered >= STR_TO_DATE('".$date_from."','%d.%m.%Y') AND
|
||||
date_entered <= STR_TO_DATE('".$date_to."','%d.%m.%Y')
|
||||
group by category_id";
|
||||
$rows = $db->query ( $query );
|
||||
|
||||
if($rows->num_rows == 0){
|
||||
// Jeśli baza nie zwróci żadnych rekordów to ustawia puste pola
|
||||
foreach($selectedColumns as $wartosc){
|
||||
$suma[] = '0,00';
|
||||
}
|
||||
// Dodatkowa kolumna na sumę
|
||||
$suma[] = '0,00';
|
||||
}else{
|
||||
$tmp2 = array();
|
||||
$sumka = 0;
|
||||
// Rekordy z bazy danych wpisujemy do tymczasowej tabeli by móc wstawić dane w odpowiednie miejsce
|
||||
while ( $r = $db->fetchByAssoc ( $rows ) ) {
|
||||
$row = array ();
|
||||
$row['category_id'] = $r['category_id'];
|
||||
$row['value'] = number_format($r['value'], 2, ",", ".");
|
||||
$sumka +=$r['value'];
|
||||
$tmp2[] = $row;
|
||||
}
|
||||
// tutaj wstawiamy w odpowiednie miejsce
|
||||
foreach($selectedColumns as $wartosc){
|
||||
$sprawdzamy = false;
|
||||
foreach($tmp2 as $cos){
|
||||
if($wartosc==$cos['category_id']){
|
||||
$sprawdzamy = true;
|
||||
$suma[] = $cos['value'];
|
||||
}
|
||||
}
|
||||
if(!$sprawdzamy){
|
||||
$suma[] = '0,00';
|
||||
}
|
||||
}
|
||||
// dodajemy ostatni wiersz sumy
|
||||
$suma[]=number_format($sumka, 2, ",", ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* ******************** SMARTY **********************
|
||||
*/
|
||||
$smarty = new Sugar_Smarty ();
|
||||
global $mod_strings;
|
||||
$smarty -> assign('MOD', $mod_strings);
|
||||
$smarty -> assign('data', $data);
|
||||
$smarty -> assign('date_from', $date_from);
|
||||
$smarty -> assign('suma', $suma);
|
||||
$smarty -> assign('date_to', $date_to );
|
||||
$smarty -> assign('dateFormat', $Calendar_daFormat);
|
||||
$smarty -> assign('selectedColumns', $selectedColumns);
|
||||
$smarty -> assign('category', $app_list_strings['document_category_dom']);
|
||||
echo $smarty->display ( 'modules/EcmReports/tpls/ReportValue.tpl' );
|
||||
?>
|
||||
19
modules/var/www/html/system/modules/EcmReports/cos.php
Normal file
19
modules/var/www/html/system/modules/EcmReports/cos.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
ini_set('display_errors',1);
|
||||
$bean = new EcmInvoiceOut();
|
||||
|
||||
// faktury
|
||||
$fk_list = $bean->get_full_list("", "ecminvoiceouts.deleted='0'");
|
||||
|
||||
echo "<pre>";
|
||||
var_dump($fk_list);
|
||||
die;
|
||||
|
||||
foreach ($fk_list as $fk){
|
||||
echo $fk->document_no.' <br>';
|
||||
$items= $fk->getPositionList(true);
|
||||
foreach ($items as $item){
|
||||
echo $item['name'].' '.$item['quantity'].'<br>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
17
modules/var/www/html/system/modules/EcmReports/createPDF.php
Normal file
17
modules/var/www/html/system/modules/EcmReports/createPDF.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
$smarty = new Sugar_Smarty ();
|
||||
$content = $smarty->fetch('modules/EcmReports/tpls/pdf_content_header.tpl');
|
||||
$content .= 'test<table id="myTable" class="tablesorter">' .$_REQUEST['dataTable'] . '</table>';
|
||||
$content .= $smarty->fetch('modules/EcmReports/tpls/pdf_content_footer.tpl');
|
||||
$mpdf = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 10, 10, 5, 5 );
|
||||
$mpdf->mirrorMargins = 1;
|
||||
|
||||
$mpdf->WriteHTML($content);
|
||||
|
||||
$dir = 'upload/' . $current_user->id . '/';
|
||||
if(!is_dir($dir)){
|
||||
mkdir($dir, '755', true);
|
||||
}
|
||||
$mpdf->Output ($dir.'Raport.pdf', 'F');
|
||||
print $dir.'Raport.pdf';
|
||||
482
modules/var/www/html/system/modules/EcmReports/ewkaCSV.php
Normal file
482
modules/var/www/html/system/modules/EcmReports/ewkaCSV.php
Normal file
@@ -0,0 +1,482 @@
|
||||
<form action="index.php">
|
||||
<input type='hidden' name='module' value='EcmReports'>
|
||||
<input type='hidden' name='action' value='ewkaCSV'>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
Data od:
|
||||
</td>
|
||||
<td>
|
||||
<input autocomplete="off" type="text" name="date_start" id="date_start" value="<?php echo ''.($_REQUEST['date_start']!='' ? $_REQUEST['date_start'] : date('01.m.Y')).'' ?>" title="" tabindex="105" size="10" maxlength="10"> (dd.mm.yyyy)
|
||||
</td>
|
||||
<td>
|
||||
<img border="0" src="themes/Sugar5/images/jscalendar.gif?s=bed8cd35065048ceebdc639ebe305e2c&c=1" alt="Wprowadź datę" id="date_start_trigger" align="absmiddle">
|
||||
<script type="text/javascript">
|
||||
Calendar.setup ({
|
||||
inputField : "date_start",
|
||||
daFormat : "%d.%m.%Y %H:%M",
|
||||
button : "date_start_trigger",
|
||||
singleClick : true,
|
||||
dateStr : "05.01.2016",
|
||||
step : 1,
|
||||
weekNumbers:false
|
||||
}
|
||||
);
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Data do:
|
||||
</td>
|
||||
<td>
|
||||
<input autocomplete="off" type="text" name="date_end" id="date_end" value="<?php echo ''.($_REQUEST['date_end']!='' ? $_REQUEST['date_end'] : date('t.m.Y')).'' ?>" title="" tabindex="105" size="10" maxlength="10"> (dd.mm.yyyy)
|
||||
</td>
|
||||
<td>
|
||||
<img border="0" src="themes/Sugar5/images/jscalendar.gif?s=bed8cd35065048ceebdc639ebe305e2c&c=1" alt="Wprowadź datę" id="date_end_trigger" align="absmiddle">
|
||||
<script type="text/javascript">
|
||||
Calendar.setup ({
|
||||
inputField : "date_end",
|
||||
daFormat : "%d.%m.%Y %H:%M",
|
||||
button : "date_end_trigger",
|
||||
singleClick : true,
|
||||
dateStr : "05.01.2016",
|
||||
step : 1,
|
||||
weekNumbers:false
|
||||
}
|
||||
);
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br><input type="submit" value="Generuj" name="submit">
|
||||
</form>
|
||||
<?php
|
||||
global $current_user;
|
||||
|
||||
class raportTxT {
|
||||
|
||||
public $fileName;
|
||||
private $db;
|
||||
private $fp;
|
||||
private $separator;
|
||||
private $nl;
|
||||
private $header;
|
||||
private $to_write;
|
||||
private $docTypes;
|
||||
private $dateFrom;
|
||||
private $dateTo;
|
||||
private $stockList;
|
||||
|
||||
function __construct($fileName, $separator, $nl,$date_start,$date_end) {
|
||||
$this->fileName = $fileName;
|
||||
$this->separator = $separator;
|
||||
$this->nl = $nl;
|
||||
$this->db = $GLOBALS['db'];
|
||||
$this->getStockList();
|
||||
$this->documentTypes();
|
||||
$this->setDateFrom(date('Y-m-d',strtotime($date_start)));
|
||||
$this->setDateTo(date('Y-m-d',strtotime($date_end)));
|
||||
$this->drawHeader();
|
||||
$this->openFile();
|
||||
$this->writeLine();
|
||||
$this->createFileContent();
|
||||
}
|
||||
|
||||
function getStockList() {
|
||||
$res = $this->db->query('SELECT id, name, tmp_number FROM ecmstocks order by tmp_number');
|
||||
$this->stockList = array();
|
||||
while ($dane = $this->db->fetchByAssoc($res)) {
|
||||
$this->stockList[$dane['id']] = $dane;
|
||||
}
|
||||
}
|
||||
|
||||
function getStockNumber($stockId) {
|
||||
return 'MG_' . $this->stockList[$stockId]['tmp_number'];
|
||||
}
|
||||
|
||||
function setDateFrom($data = NULL) {
|
||||
if (isset($data) && strlen($data) > 8) {
|
||||
try {
|
||||
$this->dateFrom = new DateTime($data);
|
||||
} catch (Exception $e) {
|
||||
$this->dateFrom = NULL;
|
||||
}
|
||||
} else {
|
||||
$this->dateFrom = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function setDateTo($data = NULL) {
|
||||
if (isset($data) && strlen($data) > 8) {
|
||||
try {
|
||||
$this->dateTo = new DateTime($data);
|
||||
} catch (Exception $e) {
|
||||
$this->dateTo = NULL;
|
||||
}
|
||||
} else {
|
||||
$this->dateTo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function getQueryWhere() {
|
||||
$check = false;
|
||||
$whereQuery = '';
|
||||
if (isset($this->dateFrom) && is_a($this->dateFrom, 'DateTime')) {
|
||||
if (!$check) {
|
||||
$check = true;
|
||||
$whereQuery = " WHERE ";
|
||||
}
|
||||
$whereQuery .= " register_date >= '" . $this->dateFrom->format("Y-m-d") ."' ";
|
||||
}
|
||||
if (isset($this->dateTo) && is_a($this->dateTo, 'DateTime')) {
|
||||
if (!$check) {
|
||||
$check = true;
|
||||
$whereQuery = " WHERE ";
|
||||
}
|
||||
$whereQuery .= " AND register_date <= '" . $this->dateTo->format("Y-m-d") . "' ";
|
||||
}
|
||||
$whereQuery.='and deleted=0 and canceled=0 ';
|
||||
if ($check) {
|
||||
return $whereQuery;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function openFile() {
|
||||
unlink($this->fileName);
|
||||
$this->fp = fopen($this->fileName, 'w+');
|
||||
}
|
||||
|
||||
function documentTypes() {
|
||||
$tmp = array();
|
||||
$tmp[] = 'EcmStockDocIn';
|
||||
$tmp[] = 'EcmStockDocOut';
|
||||
$tmp[] = 'EcmInvoiceOut';
|
||||
$tmp[] = 'EcmStockDocInsideIn';
|
||||
$tmp[] = 'EcmStockDocInsideOut';
|
||||
$tmp[] = 'EcmStockDocCorrect';
|
||||
$tmp[] = 'EcmStockDocMove';
|
||||
|
||||
$this->docTypes = $tmp;
|
||||
unset($tmp);
|
||||
}
|
||||
|
||||
function createFileContent() {
|
||||
|
||||
foreach ($this->docTypes as $key => $val) {
|
||||
$callMe = 'Get' . $val;
|
||||
|
||||
$this->$callMe($val);
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmInvoiceOut($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
// echo "<pre>";
|
||||
$tmp = array();
|
||||
|
||||
if ($dane['type'] == 'normal') {
|
||||
$tmp[] = 'FK';
|
||||
} else {
|
||||
$tmp[] = 'KF';
|
||||
}
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $dane['purchase_price'];
|
||||
$tmp[] = $dane['total_netto'];
|
||||
$tmp[] = $dane['total_vat'];
|
||||
$tmp[] = $dane['total_brutto'];
|
||||
$tmp[] = $dane['pdf_type'];
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = $a->ks_account;
|
||||
$tmp[] = $a->index_dbf;
|
||||
$tmp[] = $dane['payment_date_days'];
|
||||
$zap2 = $this->db->query("select name from ecminvoicecategories where id='".$dane['category']."'");
|
||||
$dane2 = $this->db->fetchByAssoc($zap2);
|
||||
|
||||
|
||||
$tmp[] = $dane2['name'];
|
||||
$tmp[]= $dane['currency_value_nbp'];
|
||||
$tmp[] = '';
|
||||
unset($a);
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmStockDocOut($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
global $app_list_strings;
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
$purchasePrice = 0;
|
||||
$purchasePriceResult = $this->db->query("Select quantity*price as suma from ecmstockdocoutitems WHERE ecmstockdocout_id='" . $dane['id'] . "'");
|
||||
while ($danepurchase = $this->db->fetchByAssoc($purchasePriceResult)) {
|
||||
$purchasePrice += $danepurchase['suma'];
|
||||
}
|
||||
$tmp = array();
|
||||
$tmp[] = 'WZ';
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $purchasePrice;
|
||||
$tmp[] = $dane['total_netto'];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = $a->ks_account;
|
||||
$tmp[] = $a->index_dbf;
|
||||
$tmp[] = '';
|
||||
$tmp[] = $app_list_strings['ecmstockdocouts_category_list'][$dane['category']];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
unset($a);
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmStockDocIn($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
$tmp = array();
|
||||
$tmp[] = 'PZ';
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $dane['total_netto'];
|
||||
$tmp[] = $dane['total_netto'];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = $dane['kind'];
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = $a->ks_account;
|
||||
$tmp[] = $a->index_dbf;
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
unset($a);
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmStockDocInsideIn($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
$tmp = array();
|
||||
$tmp[] = 'PW';
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$kar= new EcmProductStockIndex();
|
||||
$kar->retrieve($dane['ecmproductstockindex_id']);
|
||||
$tmp[] = $kar->name;
|
||||
unset($a);
|
||||
unset($kar);
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmStockDocInsideOut($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
$tmp = array();
|
||||
$tmp[] = 'RW';
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$kar= new EcmProductStockIndex();
|
||||
$kar->retrieve($dane['ecmproductstockindex_id']);
|
||||
$tmp[] = $kar->name;
|
||||
unset($a);
|
||||
unset($kar);
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmStockDocCorrect($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
$tmp = array();
|
||||
$tmp[] = 'KS';
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$kar= new EcmProductStockIndex();
|
||||
$kar->retrieve($dane['ecmproductstockindex_id']);
|
||||
$tmp[] = $kar->name;
|
||||
unset($a);
|
||||
unset($kar);
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function GetEcmStockDocMove($mod) {
|
||||
// echo 'wywoluje?';
|
||||
// echo '<br>';
|
||||
// echo "select * from " . strtolower($mod) . "s " . $this->getQueryWhere();
|
||||
// echo '<br>';
|
||||
$zap = $this->db->query("select * from " . strtolower($mod) . "s " . $this->getQueryWhere());
|
||||
while ($dane = $this->db->fetchByAssoc($zap)) {
|
||||
$tmp = array();
|
||||
$tmp[] = 'MM';
|
||||
$tmp[] = $dane['document_no'];
|
||||
$tmp[] = $dane['register_date'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = $dane['total'];
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = $this->getStockNumber($dane['stock_out_id']);
|
||||
$tmp[] = $this->getStockNumber($dane['stock_in_id']);
|
||||
$a = new Account();
|
||||
$a->retrieve($dane['parent_id']);
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$tmp[] = '';
|
||||
$kar= new EcmProductStockIndex();
|
||||
$kar->retrieve($dane['ecmproductstockindex_id']);
|
||||
$tmp[] = $kar->name;
|
||||
unset($a);
|
||||
unset($kar);
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
$this->writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function closeFile() {
|
||||
fclose($this->fp);
|
||||
}
|
||||
|
||||
function drawHeader() {
|
||||
$tmp = array();
|
||||
$tmp[] = 'SYMBOL DOK';
|
||||
$tmp[] = 'NR DOK';
|
||||
$tmp[] = 'DATA DOK';
|
||||
$tmp[] = 'WART MAG';
|
||||
$tmp[] = 'WART NET';
|
||||
$tmp[] = 'WART VAT';
|
||||
$tmp[] = 'WART B';
|
||||
$tmp[] = 'RODZAJ';
|
||||
$tmp[] = 'MAG ZR';
|
||||
$tmp[] = 'MAG DOC';
|
||||
$tmp[] = 'KONTO KS';
|
||||
$tmp[] = 'INDEKS';
|
||||
$tmp[] = 'DNI_PLATNOSCI';
|
||||
$tmp[] = 'KATEGORIA';
|
||||
$tmp[] = 'KURS VAL';
|
||||
$tmp[] = 'KARTOTEKA';
|
||||
|
||||
$this->to_write = implode($this->separator, $tmp) . ';';
|
||||
unset($tmp);
|
||||
}
|
||||
|
||||
function writeLine() {
|
||||
fwrite($this->fp, $this->to_write . $this->nl);
|
||||
}
|
||||
|
||||
}
|
||||
if($_REQUEST['submit']!=''){
|
||||
$name='evka.csv';
|
||||
$c = new raportTXT($name, ';', PHP_EOL,$_REQUEST['date_start'],$_REQUEST['date_end']);
|
||||
|
||||
$file=$name;
|
||||
|
||||
|
||||
header("Location: ".$name);
|
||||
}
|
||||
?>
|
||||
1
modules/var/www/html/system/modules/EcmReports/index.php
Normal file
1
modules/var/www/html/system/modules/EcmReports/index.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php include_once("modules/EcmReports/ReportSales.php");?>
|
||||
184
modules/var/www/html/system/modules/EcmReports/kpkwReport.php
Normal file
184
modules/var/www/html/system/modules/EcmReports/kpkwReport.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
||||
die ( 'Not A Valid Entry Point' );
|
||||
|
||||
/*
|
||||
* kasjer
|
||||
*/
|
||||
$user=array();
|
||||
$r=$GLOBALS['db']->query("select u.first_name,u.last_name,u.id from users as u join ecmcashs_ecmkpkw as rel on rel.user_id=u.id group by u.id");
|
||||
while($dn = $GLOBALS['db']->fetchByAssoc($r))
|
||||
$user[]=$dn;
|
||||
|
||||
/**
|
||||
* pobiera imie i nazwisko wybranego kasjera
|
||||
*
|
||||
*/
|
||||
$us=new User;
|
||||
$us->retrieve($_GET['kasjer']);
|
||||
|
||||
/**
|
||||
* EcmNewKpkws report DATE format
|
||||
*/
|
||||
require_once('include/utils.php');
|
||||
global $db,$app_strings;
|
||||
|
||||
$stop = new DateTime('NOW');
|
||||
|
||||
$start = new DateTime(date('01.m.Y'));
|
||||
|
||||
$currentTo = @$_GET['date_to'] ? : $stop->format('t.m.Y');
|
||||
$currentFrom = @$_GET['date_from'] ? : $start->format('01.m.Y');
|
||||
$Calendar_daFormat = str_replace("d","%d",str_replace("m","%m",str_replace("Y","%Y",$GLOBALS['timedate']->get_date_format())));
|
||||
|
||||
/*
|
||||
* generate query
|
||||
*
|
||||
*/
|
||||
$additionalWhereConditions = array(
|
||||
'\'' . $start->format('Y-m-01') . '\'',
|
||||
'\'' . $stop->format('Y-m-t') . '\'',
|
||||
);
|
||||
|
||||
if($from = @$_GET['date_from']) {
|
||||
$fromDate = new DateTime($from);
|
||||
$additionalWhereConditions[0] = '\'' . $fromDate->format('Y-m-d') . '\'';
|
||||
}
|
||||
|
||||
|
||||
if($to = @$_GET['date_to']) {
|
||||
$toDate = new DateTime($to);
|
||||
$additionalWhereConditions[1] = '\'' . $toDate->format('Y-m-d') . '\'';
|
||||
}
|
||||
if($_GET['ecmcash_id']!=''){
|
||||
$additionalWhereConditions[2]='cash_id=\'' . $_GET['ecmcash_id'] . '\'';
|
||||
}
|
||||
if($_GET['kasjer']!=''){
|
||||
$kasjer=" and `created_by`='".$_GET['kasjer']."'";
|
||||
}
|
||||
|
||||
|
||||
$additionalWhere = '`date_entered` BETWEEN ' . implode(' AND ', $additionalWhereConditions)." ".$kasjer;
|
||||
|
||||
|
||||
$query = '
|
||||
SELECT
|
||||
|
||||
`description`,`description`,`amount`,`document_no`,
|
||||
`parent_address_street`,`parent_address_city`,`parent_address_postalcode`,
|
||||
`parent_address_country`,`parent_contact_name`,`parent_contact_title`,
|
||||
`date_entered`,`type_id`,`parent_name`
|
||||
|
||||
FROM `ecmnewkpkws`
|
||||
|
||||
WHERE
|
||||
' . (additionalWhere ? ($additionalWhere) : '') . '
|
||||
|
||||
ORDER BY
|
||||
|
||||
`date_entered` ASC;
|
||||
';
|
||||
|
||||
$result = $db->query($query);
|
||||
$query_bo = "SELECT SUM(IF(type_id = 0, amount, -amount)) AS `sum` FROM `ecmnewkpkws` WHERE `date_entered` < ".$additionalWhereConditions[0]." ".$kasjer;
|
||||
|
||||
$result_bo = $db->query($query_bo);
|
||||
if($row_bo = $db->fetchByAssoc($db->query($query_bo)))
|
||||
{
|
||||
$bo = $row_bo["sum"];
|
||||
|
||||
}
|
||||
$date=array();
|
||||
$i=1;
|
||||
while($row = $db->fetchByAssoc($result)){
|
||||
$row['type_id']==0 ? $date['in']+=$row['amount'] : $date['out']+=$row['amount'];
|
||||
$i%2 ? $row['class']='even' : $row['class']='odd';
|
||||
$row['number']=$i;
|
||||
$date[]=$row;
|
||||
$i++;
|
||||
}
|
||||
|
||||
// create & execute smarty
|
||||
$smarty = new Sugar_Smarty ();
|
||||
global $mod_strings;
|
||||
|
||||
|
||||
$smarty->assign ( "MOD", $mod_strings );
|
||||
$smarty->assign ( "DATA", $date );
|
||||
$smarty->assign ( "CASH_BEFORE", $bo );
|
||||
$smarty->assign ( "CASH_NOW",(($bo+$date['in'])-$date['out']));
|
||||
$smarty->assign ( "STOCKS", $datastocks );
|
||||
$smarty->assign ( "PARAMS", $_GET);
|
||||
$smarty->assign ( "USER_NAME",$us->full_name);
|
||||
$smarty->assign ( "USERS", $user);
|
||||
$smarty->assign ( "currentTo", $currentTo);
|
||||
$smarty->assign ( "currentFrom", $currentFrom);
|
||||
$smarty -> assign("dateFormat", $Calendar_daFormat);
|
||||
|
||||
if( $_GET['toPDF'] == '1' ) {
|
||||
if( $_GET['to_xls'] == '1' ) {
|
||||
|
||||
|
||||
$header=array();
|
||||
$header[]='numer dokumentu';
|
||||
$header[]='data';
|
||||
$header[]='tytuł';
|
||||
$header[]='kontrahent';
|
||||
$header[]='przychód';
|
||||
$header[]='rozchód';
|
||||
|
||||
$filename='modules/Home/Files/raport_kasowy_'.date('d_m-Y').'.csv';
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
foreach ($date as $key=>$val){
|
||||
if($val['type_id']!=''){
|
||||
|
||||
$line=array();
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['document_no']))).'"""';
|
||||
$line[]=$val['date_entered'];
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['description']))).'"""';
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['parent_name'])));
|
||||
if($poz.type_id==0){
|
||||
$line[]=str_replace(".",",",$val['amount']);
|
||||
$line[]=str_replace(".",",",$val['wartosc']);
|
||||
} else {
|
||||
$line[]=str_replace(".",",",$val['wartosc']);
|
||||
$line[]=str_replace(".",",",$val['amount']);
|
||||
}
|
||||
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
header("Location: ". $filename);
|
||||
} else {
|
||||
$output = $smarty->fetch( 'modules/EcmReports/tpls/PDF/kpkwReport.tpl' );
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
unset($smarty);
|
||||
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 26, 10, 5, 5 );
|
||||
$p->setFooter('Strona {PAGENO} z {nbpg}');
|
||||
$kasa=$_GET['cash_name']!='' ? '<br>Kasa: '.$_GET['cash_name'] : '';
|
||||
$usr=$_GET['kasjer']!='' ? '<br>Kasjer: '.$us->full_name : '';
|
||||
$p->SetHTMLHeader('<p style="text-align:left;font-size: 10px;">Saas SystemS Sp. z o.o.<br>
|
||||
Raport kasowy<br>Raport od '.date('d.m.Y',strtotime($currentFrom)).' do '.date('d.m.Y',strtotime($currentTo)).' <br>Data wydruku: '.date("d.m.Y").' '.$kasa.' '.$usr.'</p>');
|
||||
//$p->setTitle($mod_strings["LBL_REPORT_STOCKS_DOCS"]);
|
||||
//echo $output;
|
||||
$p->writeHTML( $output );
|
||||
|
||||
$p->Output ();
|
||||
}
|
||||
} else {
|
||||
$smarty->display ( 'modules/EcmReports/tpls/kpkwReport.tpl' );
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: Defines the English language pack for the base application.
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
$mod_strings = array (
|
||||
'LBL_REPORT_STOCKS' => 'Stock States Report',
|
||||
'LBL_STOCK' => 'Stock',
|
||||
'LBL_PRODUCT_ACTIVE' => 'Product Active',
|
||||
'LBL_YES' => 'Yes',
|
||||
'LBL_NO' => 'No',
|
||||
'LBL_ASSIGNED_TO_ID' => 'Assigned To',
|
||||
'LBL_VALUE' => 'Value',
|
||||
'LBL_MODULE_NAME' => 'Sales Report',
|
||||
'LBL_MODULE_TITLE' => 'Sales Report: Home',
|
||||
'LBL_MODULE_ID' => 'Sales Report',
|
||||
'LBL_SEARCH_FORM_TITLE' => 'Sales Report Search',
|
||||
'LBL_LIST_FORM_TITLE' => 'Sales Report List',
|
||||
'LBL_NEW_FORM_TITLE' => 'New Sales Report',
|
||||
'LBL_SUBJECT' => 'Subject:',
|
||||
'LBL_ECMREPORT' => 'Sales Report:',
|
||||
'LBL_ECMREPORT_SUBJECT' => 'Sales Report Subject:',
|
||||
'LBL_LIST_SUBJECT' => 'Name',
|
||||
'LBL_LIST_LAST_MODIFIED' => 'Last Modified',
|
||||
'LNK_NEW_ECMREPORT' => 'Create Sales Report',
|
||||
'LNK_ECMREPORT_LIST' => 'Sales Report',
|
||||
'ERR_DELETE_RECORD' => 'You must specify a record number in order to delete the vat.',
|
||||
'LBL_LIST_MY_ECMREPORTS' => 'My Assigned Sales Report',
|
||||
|
||||
'LBL_CREATED_BY' => 'Created by:',
|
||||
'LBL_DATE_CREATED' => 'Create Date:',
|
||||
'LBL_MODIFIED_BY' => 'Last Modified by:',
|
||||
'LBL_DATE_LAST_MODIFIED' => 'Modify Date:',
|
||||
|
||||
'LBL_DEFAULT_SUBPANEL_TITLE' => 'Sales Report',
|
||||
'LBL_SYSTEM_ID' => 'System ID',
|
||||
'LBL_LIST_ASSIGNED_TO_NAME' => 'Assigned User',
|
||||
'LBL_LIST_VALUE' => 'Value',
|
||||
'LBL_ASSIGNED_TO_NAME' => 'Assigned to',
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*********************************************************************************
|
||||
|
||||
* Description: Defines the English language pack for the base application.
|
||||
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________..
|
||||
********************************************************************************/
|
||||
$mod_strings = array (
|
||||
'LBL_ASSIGNED_TO_ID' => 'Assigned To',
|
||||
'LBL_VALUE' => 'Value',
|
||||
'LBL_MODULE_NAME' => 'Vat',
|
||||
'LBL_MODULE_TITLE' => 'Vat: Home',
|
||||
'LBL_MODULE_ID' => 'Vat',
|
||||
'LBL_SEARCH_FORM_TITLE' => 'Vat Search',
|
||||
'LBL_LIST_FORM_TITLE' => 'Vat List',
|
||||
'LBL_NEW_FORM_TITLE' => 'New Vat',
|
||||
'LBL_SUBJECT' => 'Subject:',
|
||||
'LBL_ECMREPORT' => 'Vat:',
|
||||
'LBL_ECMREPORT_SUBJECT' => 'Vat Subject:',
|
||||
'LBL_LIST_SUBJECT' => 'Name',
|
||||
'LBL_LIST_LAST_MODIFIED' => 'Last Modified',
|
||||
'LNK_NEW_ECMREPORT' => 'Create Vat',
|
||||
'LNK_ECMREPORT_LIST' => 'Vat',
|
||||
'ERR_DELETE_RECORD' => 'You must specify a record number in order to delete the vat.',
|
||||
'LBL_LIST_MY_ECMREPORTS' => 'My Assigned Vat',
|
||||
|
||||
'LBL_CREATED_BY' => 'Created by:',
|
||||
'LBL_DATE_CREATED' => 'Create Date:',
|
||||
'LBL_MODIFIED_BY' => 'Last Modified by:',
|
||||
'LBL_DATE_LAST_MODIFIED' => 'Modify Date:',
|
||||
|
||||
'LBL_DEFAULT_SUBPANEL_TITLE' => 'Vat',
|
||||
'LBL_SYSTEM_ID' => 'System ID',
|
||||
'LBL_LIST_ASSIGNED_TO_NAME' => 'Assigned User',
|
||||
'LBL_LIST_VALUE' => 'Value',
|
||||
'LBL_ASSIGNED_TO_NAME' => 'Assigned to',
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
$mod_strings = array (
|
||||
'LBL_MODULE_NAME' => 'Raporty',
|
||||
'LBL_MODULE_TITLE' => 'Raporty: Strona Główna',
|
||||
'LBL_MODULE_ID' => 'Raporty',
|
||||
'LBL_REPORT_SALES_BY_PRODUCT' => 'Raport Sprzedaży - Ilościowy',
|
||||
'LBL_REPORT_SALES_BY_CONTRACTOR' => 'Raport Sprzedaży - Według Nabywców',
|
||||
'LBL_REPORT_SALES_BY_DOCUMENT' => 'Raport Sprzedaży - Raport wartościowy',
|
||||
'LBL_REPORT_SALES_BY_GROUP' => 'Raport sprzedaż w grupach',
|
||||
'LBL_REPORT_SALES_ANALIS_PRODUCT' => 'Raport Sprzedaży - Analiza sprzedaży produktów',
|
||||
'LBL_REPORT_SALES_VAT_SALES' => 'Raport Sprzedaży - Rejestr sprzedaży VAT',
|
||||
'LBL_REPORT_SALES_ANALYSIS_ECMQUOTE' => 'Raport Sprzedaży - Skuteczność ofert',
|
||||
'LBL_REPORT_STOCKS_STOCK_STATE' => 'Raport Magazynowy - Stany magazynowe',
|
||||
'LBL_DATE_FROM' => 'Data od',
|
||||
'LBL_DATE_TO' => 'Data do',
|
||||
'LBL_EXECUTE' => 'Wykonaj',
|
||||
'LBL_CLEAR' => 'Wyczyść',
|
||||
'LBL_PDF' => 'PDF',
|
||||
'LBL_SALES_BRUTTO' => 'Sprzedaż brutto',
|
||||
'LBL_DOCUMENT' => 'Dokument',
|
||||
'LBL_DOCUMENT_SALES_TYPE' => 'Typ dokumentu',
|
||||
'DOCUMENT_SALES_LIST' => array(
|
||||
'' => '',
|
||||
'invoice' => 'Faktura',
|
||||
'invoice_correct' =>'Faktura korekta',
|
||||
'recipe' => 'Paragon',
|
||||
'recipe_correct' => 'Paragon korekta',
|
||||
),
|
||||
'LBL_PRODUCT_GROUP' => 'Grupa',
|
||||
'TIP_MULTIPLE' => 'By zaznaczyć/odznaczyć kilka opcji wciśnij CTRL i kliknij na porządane elementy',
|
||||
'LBL_TRADER' => 'Handlowiec',
|
||||
'LBL_STOCK' => 'Magazyn',
|
||||
'TIP_CHOOSE_TRADER' => 'Wybierz Sprzedawcę',
|
||||
'TIP_CHOOSE_ACCOUNT' => 'Wybierz Kontrahenta',
|
||||
'LBL_PRODUCTS_CATEGORY' => 'Kategoria produktowa',
|
||||
'LBL_PRODUCT' => 'Produkt',
|
||||
'LBL_CONTRACTOR' => 'Kontrahent',
|
||||
'LBL_NETTO' => 'Netto',
|
||||
'LBL_BRUTTO' => 'Brutto',
|
||||
'LBL_PURCHASE' => 'Zakup',
|
||||
'LBL_INCOME' => 'Dochód',
|
||||
'LBL_OVERHEAD' => 'Narzut',
|
||||
'LBL_NAME' => 'Nazwa',
|
||||
'LBL_SUMMARY' => 'Suma',
|
||||
'LBL_QUANTITY' => 'Ilość',
|
||||
'LBL_JM' => 'jm',
|
||||
'LBL_SALES_NETTO' => 'Sprzedaż Netto',
|
||||
'LBL_COST_PURCHASE' => 'Koszt Zakupu',
|
||||
'LBL_INCOME_OVERHEAD' => 'Dochód (Narzut)',
|
||||
'LBL_YES' => 'Tak',
|
||||
'LBL_NO' => 'Nie',
|
||||
'LBL_PRODUCT_ACTIVE' => 'Produkt aktywny',
|
||||
'LBL_INDEX' => 'Indeks',
|
||||
'LBL_PRICE' => 'Cena',
|
||||
'LBL_CONSIGNMENTS'=>'Partia',
|
||||
'LBL_DOCUMENT_DATE' => 'Data dokumentu',
|
||||
'LBL_DOCUMENT_TYPE' => 'Rodzaj dokumentu',
|
||||
'LBL_REPORT_ACCEPTANCE' => 'Raport akceptacji',
|
||||
'LBL_REPORT_ACCEPTANCE_DOCNAME' => 'Nazwa dokumentu',
|
||||
'LBL_REPORT_ACCEPTANCE_ACCOUNT' => 'Przywiązane do',
|
||||
'LBL_REPORT_ACCEPTANCE_CATEGORY' => 'Kategoria',
|
||||
'LBL_REPORT_ACCEPTANCE_DES' => 'Opis',
|
||||
'LBL_REPORT_ACCEPTANCE_NAME' => 'Nazwa uzytkownika',
|
||||
'LBL_REPORT_ACCEPTANCE_DOCDATE' => 'Data dokumentu',
|
||||
// kpkw report
|
||||
// RAPORT && PDF
|
||||
'LBL_NUMBER_LP' => 'Lp',
|
||||
'LBL_DOCUMENT_NO' => 'Nr dokumentu',
|
||||
'LBL_CREATE_LAB' => 'Data wyst.',
|
||||
'LBL_TITLE' => 'Tytuł',
|
||||
'LBL_PARENT_NAME' => 'Kontrahent',
|
||||
'LBL_AMOUNT_PLUS' => 'Przychód',
|
||||
'LBL_AMOUNT_MINUS' => 'Rozchód',
|
||||
'LBL_VALUE' => 'Suma',
|
||||
'LBL_VALUE_BEFORE' => 'Stan kasy poprzednio',
|
||||
'LBL_VALUE_TOTAL' => 'Stan kasy obecny',
|
||||
'LBL_RAPORT_TITLE' => 'Zestawienie KPKW',
|
||||
'LBL_RAPORT_TITLE2' => 'RAPORT KASOWY',
|
||||
'LBL_RAPORT_LABEL' => 'Raport kasowy',
|
||||
'LBL_TIME' => 'okres',
|
||||
'LBL_TIME2' => 'Okres',
|
||||
'LBL_CASH' => 'kasa',
|
||||
'LBL_CURRENCY_PDF' => 'waluta',
|
||||
'LBL_CURRENCY_PDF2' => 'Waluta',
|
||||
'LBL_CASH_USER' => 'kasjer',
|
||||
'LBL_DATE_START' => 'Od',
|
||||
'LBL_DATE_END' => 'Do',
|
||||
'LBL_CASH2' => 'Kasa',
|
||||
'LBL_CASH_USER2' => 'Kasjer',
|
||||
'LBL_SUBMIT' => 'Wykonaj',
|
||||
'LBL_SELECT' => 'Wybierz',
|
||||
'LBL_ALL' => 'Wszyscy',
|
||||
'LBL_PRINT_PDF' => 'Drukuj PDF',
|
||||
'LBL_SALE_DATE' => 'Data sprz.',
|
||||
'LBL_CONTRACTOR_NIP' => 'Nip odbiorcy',
|
||||
'LBL_ADDRESS' => 'Adres',
|
||||
'LBL_GROSS_SALES' => 'Sprz. brutto',
|
||||
'LBL_NET_SALES' => 'Sprz. netto',
|
||||
'LBL_VAT' => 'Vat',
|
||||
'LBL_SUM_VAT' => 'Vat razem',
|
||||
'LBL_VAT_SALES_REGISTER' => "Rejestr sprzedaży VAT",
|
||||
'LBL_COST_OF' => "Koszt własny",
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
$searchFields['EcmReports'] =
|
||||
array (
|
||||
'name' => array( 'query_type'=>'default'),
|
||||
'value' => array( 'query_type'=>'default'),
|
||||
'current_user_only'=> array('query_type'=>'default','db_field'=>array('assigned_user_id'),'my_items'=>true),
|
||||
'assigned_user_id'=> array('query_type'=>'default'),
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
*********************************************************************************/
|
||||
|
||||
require_once('include/utils.php');
|
||||
|
||||
function additionalDetailsEcmReport($fields) {
|
||||
static $mod_strings;
|
||||
global $app_strings;
|
||||
if(empty($mod_strings)) {
|
||||
global $current_language;
|
||||
$mod_strings = return_module_language($current_language, 'EcmReports');
|
||||
}
|
||||
|
||||
$overlib_string = '';
|
||||
|
||||
if(!empty($fields['DATE_ENTERED']))
|
||||
$overlib_string .= '<b>'. $app_strings['LBL_DATE_ENTERED'] . '</b> ' . $fields['DATE_ENTERED'] . '<br>';
|
||||
if(!empty($fields['NAME']))
|
||||
$overlib_string .= '<b>'. $mod_strings['LBL_NAME'] . '</b> ' . $fields['NAME'] . '<br>';
|
||||
|
||||
return array('fieldToAddTo' => 'NAME',
|
||||
'string' => $overlib_string,
|
||||
'editLink' => "index.php?action=EditView&module=EcmReports&return_module=EcmReports&record={$fields['ID']}",
|
||||
'viewLink' => "index.php?action=DetailView&module=EcmReports&return_module=EcmReports&record={$fields['ID']}");
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
$viewdefs['EcmReports']['DetailView'] = array(
|
||||
'templateMeta'=>array(
|
||||
'form'=>array(
|
||||
'buttons'=>array(
|
||||
'EDIT',
|
||||
'DUPLICATE',
|
||||
'DELETE',
|
||||
)
|
||||
),
|
||||
'maxColumns'=>'2',
|
||||
'widths'=>array(
|
||||
array(
|
||||
'label'=>'10',
|
||||
'field' =>'30'
|
||||
),
|
||||
array(
|
||||
'label'=>'10',
|
||||
'field'=>'30'
|
||||
)
|
||||
),
|
||||
),
|
||||
'panels'=>array(
|
||||
array(
|
||||
'name',
|
||||
'assigned_user_name',
|
||||
),
|
||||
array(
|
||||
'value',
|
||||
),
|
||||
)
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
$viewdefs['EcmReports']['EditView'] = array(
|
||||
'templateMeta'=>array(
|
||||
'form' => array('buttons'=>array('SAVE', 'CANCEL')),
|
||||
'maxColumns'=>'2',
|
||||
'widths'=>array(
|
||||
array('label'=>'10','field'=>'30'),
|
||||
array('label'=>'10','field'=>'30'),
|
||||
),
|
||||
),
|
||||
'panels'=>array(
|
||||
'default'=>array(
|
||||
array('name','assigned_user_name'),
|
||||
array('value'),
|
||||
),
|
||||
),
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/**
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
$listViewDefs['EcmReports'] = array(
|
||||
'NAME' => array(
|
||||
'width' => '32',
|
||||
'label' => 'LBL_LIST_SUBJECT',
|
||||
'default' => true,
|
||||
'link' => true),
|
||||
'VALUE' => array(
|
||||
'width' => '10',
|
||||
'label' => 'LBL_LIST_VALUE',
|
||||
'default' => true),
|
||||
'ASSIGNED_USER_NAME' => array(
|
||||
'width' => '9',
|
||||
'label' => 'LBL_LIST_ASSIGNED_USER',
|
||||
'default' => true)
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*
|
||||
* Created on Jun 1, 2007
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
$metafiles['EcmReports'] = array(
|
||||
'detailviewdefs' => 'modules/EcmReports/metadata/detailviewdefs.php',
|
||||
'editviewdefs' => 'modules/EcmReports/metadata/editviewdefs.php',
|
||||
'listviewdefs' => 'modules/EcmReports/metadata/listviewdefs.php',
|
||||
'searchdefs' => 'modules/EcmReports/metadata/searchdefs.php',
|
||||
'popupdefs' => 'modules/EcmReports/metadata/popupdefs.php',
|
||||
'searchfields' => 'modules/EcmReports/metadata/SearchFields.php',
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
$popupMeta = array('moduleMain' => 'EcmReport',
|
||||
'varName' => 'ECMREPORT',
|
||||
'orderBy' => 'ecmreports.name',
|
||||
'whereClauses' =>
|
||||
array('name' => 'ecmreports.name'),
|
||||
'listviewdefs' => array(
|
||||
'NAME' => array(
|
||||
'width' => '32',
|
||||
'label' => 'LBL_LIST_SUBJECT',
|
||||
'default' => true,
|
||||
'link' => true),
|
||||
'VALUE' => array(
|
||||
'width' => '10',
|
||||
'label' => 'LBL_LIST_VALUE',
|
||||
'default' => true),
|
||||
'ASSIGNED_USER_NAME' => array(
|
||||
'width' => '9',
|
||||
'label' => 'LBL_LIST_ASSIGNED_USER',
|
||||
'default' => true)
|
||||
|
||||
),
|
||||
'searchdefs' => array(
|
||||
'name',
|
||||
'value',
|
||||
array('name' => 'assigned_user_id', 'type' => 'enum', 'label' => 'LBL_ASSIGNED_TO', 'function' => array('name' => 'get_user_array', 'params' => array(false))),
|
||||
)
|
||||
);
|
||||
?>
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/*
|
||||
* Created on May 29, 2007
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
$searchdefs['EcmReports'] = array(
|
||||
'templateMeta' => array(
|
||||
'maxColumns' => '3',
|
||||
'widths' => array('label' => '10', 'field' => '30'),
|
||||
),
|
||||
'layout' => array(
|
||||
'basic_search' => array(
|
||||
'name',
|
||||
array('name'=>'current_user_only', 'label'=>'LBL_CURRENT_USER_FILTER', 'type'=>'bool'),
|
||||
),
|
||||
'advanced_search' => array(
|
||||
'name',
|
||||
'value',
|
||||
array('name' => 'assigned_user_id', 'type' => 'enum', 'label' => 'LBL_ASSIGNED_TO', 'function' => array('name' => 'get_user_array', 'params' => array(false))),
|
||||
),
|
||||
),
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
*********************************************************************************/
|
||||
$viewdefs['EcmReports']['SideQuickCreate'] = array(
|
||||
'templateMeta' => array('form'=>array('buttons'=>array('SAVE'),
|
||||
'button_location'=>'bottom',
|
||||
'headerTpl'=>'include/EditView/header.tpl',
|
||||
'footerTpl'=>'include/EditView/footer.tpl',
|
||||
),
|
||||
'maxColumns' => '1',
|
||||
'panelClass'=>'none',
|
||||
|
||||
'labelsOnTop'=>true,
|
||||
'widths' => array(
|
||||
array('label' => '10', 'field' => '30'),
|
||||
),
|
||||
),
|
||||
'panels' =>array (
|
||||
'DEFAULT' =>
|
||||
array (
|
||||
array (
|
||||
array('name'=>'name', 'displayParams'=>array('size'=>20, 'required'=>true)),
|
||||
),
|
||||
array(
|
||||
array('name'=>'value', 'displayParams'=>array('size'=>20)),
|
||||
),
|
||||
array (
|
||||
array('name'=>'assigned_user_name', 'displayParams'=>array('required'=>true, 'size'=>11, 'selectOnly'=>true)),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
)
|
||||
|
||||
|
||||
);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/**
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
*/
|
||||
|
||||
|
||||
|
||||
$GLOBALS['studioDefs']['EcmReports'] = array(
|
||||
'LBL_DETAILVIEW'=>array(
|
||||
'template'=>'xtpl',
|
||||
'template_file'=>'modules/EcmReports/DetailView.html',
|
||||
'php_file'=>'modules/EcmReports/DetailView.php',
|
||||
'type'=>'DetailView',
|
||||
),
|
||||
'LBL_EDITVIEW'=>array(
|
||||
'template'=>'xtpl',
|
||||
'template_file'=>'modules/EcmReports/EditView.html',
|
||||
'php_file'=>'modules/EcmReports/EditView.php',
|
||||
'type'=>'EditView',
|
||||
),
|
||||
'LBL_LISTVIEW'=>array(
|
||||
'template'=>'listview',
|
||||
'meta_file'=>'modules/EcmReports/listviewdefs.php',
|
||||
'type'=>'ListView',
|
||||
),
|
||||
'LBL_SEARCHFORM'=>array(
|
||||
'template'=>'xtpl',
|
||||
'template_file'=>'modules/EcmReports/SearchForm.html',
|
||||
'php_file'=>'modules/EcmReports/ListView.php',
|
||||
'type'=>'SearchForm',
|
||||
),
|
||||
|
||||
);
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/**
|
||||
* Layout definition for EcmReports
|
||||
*
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
*/
|
||||
|
||||
$layout_defs['EcmReports']['subpanel_setup'] = array(
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/**
|
||||
* Subpanel Layout definition for EcmReports
|
||||
*
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
*/
|
||||
|
||||
|
||||
$subpanel_layout = array(
|
||||
'top_buttons' => array(
|
||||
array('widget_class' => 'SubPanelTopCreateButton'),
|
||||
array('widget_class' => 'SubPanelTopSelectButton', 'popup_module' => 'EcmReports'),
|
||||
),
|
||||
|
||||
'where' => '',
|
||||
|
||||
|
||||
|
||||
'list_fields' => array(
|
||||
'ecmreport_number'=>array(
|
||||
'vname' => 'LBL_LIST_NUMBER',
|
||||
'width' => '5%',
|
||||
),
|
||||
|
||||
'name'=>array(
|
||||
'vname' => 'LBL_LIST_SUBJECT',
|
||||
'widget_class' => 'SubPanelDetailViewLink',
|
||||
'width' => '50%',
|
||||
),
|
||||
'status'=>array(
|
||||
'vname' => 'LBL_LIST_STATUS',
|
||||
'width' => '15%',
|
||||
),
|
||||
'type'=>array(
|
||||
'vname' => 'LBL_LIST_TYPE',
|
||||
'width' => '15%',
|
||||
),
|
||||
'priority'=>array(
|
||||
'vname' => 'LBL_LIST_PRIORITY',
|
||||
'width' => '11%',
|
||||
),
|
||||
'assigned_user_name' => array (
|
||||
'name' => 'assigned_user_name',
|
||||
'vname' => 'LBL_LIST_ASSIGNED_TO_NAME',
|
||||
),
|
||||
'edit_button'=>array(
|
||||
'widget_class' => 'SubPanelEditButton',
|
||||
'module' => 'EcmReports',
|
||||
'width' => '4%',
|
||||
),
|
||||
'remove_button'=>array(
|
||||
'widget_class' => 'SubPanelRemoveButton',
|
||||
'module' => 'EcmReports',
|
||||
'width' => '5%',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,404 @@
|
||||
<?php
|
||||
/*
|
||||
* author: Michał Zieliński, mz@bim-it.pl
|
||||
* created: 17.08.2015
|
||||
* last modified date: 10.09.2015 by MZ
|
||||
*/
|
||||
$process = false;
|
||||
if ($_REQUEST['process'] == "1") $process = true;
|
||||
|
||||
$db = $GLOBALS['db'];
|
||||
//create search form
|
||||
$ss = new Sugar_Smarty ();
|
||||
//group accounts
|
||||
if ($_REQUEST['group_accounts'] == "on") {
|
||||
$group_accounts = true;
|
||||
$ss->assign("GROUP_ACCOUNTS", "1");
|
||||
}
|
||||
//get Stocks
|
||||
$stocks = "";
|
||||
if ($_REQUEST['stocks']) $stocks = $_REQUEST['stocks'];
|
||||
$s_res = $db->query("SELECT id, name FROM ecmstocks WHERE deleted='0' ORDER BY name");
|
||||
$stocks_tpl = '<select multiple id="stocks" name="stocks[]">';
|
||||
$s_stocks = "";
|
||||
while ($s_row = $db->fetchByAssoc($s_res)) {
|
||||
$stocks_tpl .= '<option value="'.$s_row['id'].'"';
|
||||
if ($stocks=="" || in_array($s_row['id'], $stocks)) {
|
||||
$stocks_tpl .= " selected ";
|
||||
$s_stocks.= $s_row['name'].", ";
|
||||
}
|
||||
$stocks_tpl .= '>'.$s_row['name'].'</option>';
|
||||
}
|
||||
$stocks_tpl .= '</select>';
|
||||
$s_stocks = substr($s_stocks,0,-2);
|
||||
if (is_array($stocks) && sizeof($stocks) == $s_res->num_rows)
|
||||
$s_stocks = "Wszystkie";
|
||||
$ss->assign("STOCKS", $stocks_tpl);
|
||||
//document categories
|
||||
$categories = "";
|
||||
if ($_REQUEST['categories']) $categories = $_REQUEST['categories'];
|
||||
$s_categories = "";
|
||||
global $app_list_strings;
|
||||
$categories_def = $app_list_strings['ecminvoiceouts_category_dom'];
|
||||
if ($_REQUEST['categories']) $categories = $_REQUEST['categories'];
|
||||
$categories_tpl = '<select multiple id="categories" name="categories[]">';
|
||||
foreach ($categories_def as $k=>$v) {
|
||||
$categories_tpl .= '<option value="'.$k.'"';
|
||||
if ($categories == "" || in_array($k, $categories)) {
|
||||
$categories_tpl .= ' selected';
|
||||
$s_categories.= $v.", ";
|
||||
}
|
||||
$categories_tpl .= '>'.$v.'</option>';
|
||||
}
|
||||
$categories_tpl .= '</select>';
|
||||
$s_categories = substr($s_categories,0,-2);
|
||||
if (is_array($categories) && sizeof($categories) == sizeof($categories_def))
|
||||
$s_categories = "Wszystkie";
|
||||
$ss->assign("CATEGORIES", $categories_tpl);
|
||||
//document kinds
|
||||
$kinds_def = array (
|
||||
'K' => 'Kraj',
|
||||
'U' => 'Unia',
|
||||
'E' => 'Import',
|
||||
);
|
||||
$kinds = "";
|
||||
if ($_REQUEST['kinds']) $kinds = $_REQUEST['kinds'];
|
||||
$s_kinds = "";
|
||||
$kinds_tpl = '<select multiple id="kinds" name="kinds[]">';
|
||||
foreach ($kinds_def as $k=>$v) {
|
||||
$kinds_tpl .= '<option value="'.$k.'"';
|
||||
if ($kinds == "" || in_array($k, $kinds)) {
|
||||
$kinds_tpl .= ' selected';
|
||||
$s_kinds.=$v.", ";
|
||||
}
|
||||
$kinds_tpl .= '>'.$v.'</option>';
|
||||
}
|
||||
$kinds_tpl .= '</select>';
|
||||
$s_kinds = substr($s_kinds,0,-2);
|
||||
if (is_array($kinds) && sizeof($kinds) == sizeof($kinds_def))
|
||||
$s_kinds = "Wszystkie";
|
||||
$ss->assign("KINDS", $kinds_tpl);
|
||||
//dates
|
||||
if ($_REQUEST['date_from'])
|
||||
$date_from = $_REQUEST['date_from'];
|
||||
else {
|
||||
$date_from = new DateTime("first day of last month");
|
||||
$date_from = $date_from->format('d.m.Y');
|
||||
}
|
||||
$date_from_db = implode('-', array_reverse(explode('.', $date_from)));
|
||||
|
||||
$ss->assign("DATE_FROM", $date_from);
|
||||
|
||||
if ($_REQUEST['date_to'])
|
||||
$date_to = $_REQUEST['date_to'];
|
||||
else {
|
||||
$date_to = new DateTime("last day of last month");
|
||||
$date_to = $date_to->format('d.m.Y');
|
||||
}
|
||||
$date_to_db = implode('-', array_reverse(explode('.', $date_to)));
|
||||
$ss->assign("DATE_TO", $date_to);
|
||||
|
||||
if (!$process == true) {
|
||||
$ss->display ( 'modules/EcmReports/tpls/VatPurchasesSearch.tpl' );
|
||||
return;
|
||||
}
|
||||
|
||||
//Do your job!
|
||||
$main_query = "SELECT id, value, currency_id, currency_value, document_number, active_date, register_date FROM documents WHERE deleted='0' AND value IS NOT NULL ";
|
||||
$main_query.= "AND register_date >= '$date_from_db' AND register_date <= '$date_to_db' ";
|
||||
if($_REQUEST['categories'][0]==' '){
|
||||
$s_categories = "Wszystkie";
|
||||
} else {
|
||||
if (is_array($categories))
|
||||
$main_query .= " AND (category IN ('".implode("','", $categories)."') OR category IS NULL)";
|
||||
}
|
||||
|
||||
//if ($group_accounts == true)
|
||||
$main_query .= " ORDER BY register_date, date_entered";
|
||||
$doc_res = $db->query($main_query);
|
||||
//get vats names
|
||||
$main_query = str_replace(", value, currency_id, currency_value, document_number, active_date, register_date", "", $main_query); //leave only id field
|
||||
$vats_query = "SELECT DISTINCT vat_value as ecmvat_name, vat_id as value FROM documents_vat
|
||||
WHERE netto != 0 AND document_id IN ($main_query) ORDER BY ecmvat_name";
|
||||
$v_res = $db->query($vats_query);
|
||||
$vats = array();
|
||||
$vatsCount = 0;
|
||||
while ($v_row = $db->fetchByAssoc($v_res)) {
|
||||
//check if value is 0
|
||||
if ($v_row['value'] == 0) {
|
||||
$vats[$v_row['ecmvat_name']] = 1; //var is 0 - we didn't have to draw column
|
||||
$vatsCount++;
|
||||
} else {
|
||||
$vats[$v_row['ecmvat_name']] = 2;
|
||||
$vatsCount+=2;
|
||||
}
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$c = 1; //counter
|
||||
while ($row = $db->fetchByAssoc($doc_res)) {
|
||||
$tmp = array();
|
||||
$tmp['document_no'] = $row['document_number'];
|
||||
$tmp['register_date'] = implode('.', array_reverse(explode('-', $row['register_date'])));
|
||||
$tmp['publish_date'] = implode('.', array_reverse(explode('-', $row['active_date'])));
|
||||
|
||||
//get Account info
|
||||
$a_res = $db->fetchByAssoc($db->query("SELECT parent_id FROM documents_accounts WHERE parent_type='Account' AND deleted='0' AND document_id='".$row['id']."' LIMIT 0,1"));
|
||||
$a = new Account();
|
||||
$a->retrieve($a_res['parent_id']);
|
||||
|
||||
$pi = $a->to_vatid;
|
||||
if (strlen($pi.", ".$a->name) <= 70)
|
||||
$pi.=", ".$a->name;
|
||||
if (strlen($pi.", ".$a->register_address_street) <= 70)
|
||||
$pi.=", ".$a->register_address_street;
|
||||
if (strlen($pi.", ".$a->register_address_postalcode) <= 70)
|
||||
$pi.=", ".$a->register_address_postalcode;
|
||||
if (strlen($pi.", ".$a->register_address_city) <= 70)
|
||||
$pi.=", ".$a->register_address_city;
|
||||
$tmp['parent_info'] = $pi;
|
||||
$tmp['parent_index'] = $a->index_dbf;
|
||||
$tmp['parent_id'] = $a->id;
|
||||
$tmp['parent_type'] = $a->invoice_type;
|
||||
unset($a);
|
||||
if (!in_array($tmp['parent_type'], $kinds)) continue;
|
||||
|
||||
//get PZ info if existst
|
||||
$pz_res = $db->query("SELECT parent_id FROM documents_accounts WHERE parent_type='EcmStockDocIn' AND deleted='0' AND document_id='".$row['id']."'");
|
||||
$tmp['rel_doc'] = "";
|
||||
$tmp['rel_doc_total'] = 0;
|
||||
$stock_ok = true;
|
||||
if ($pz_res->num_rows > 0) {
|
||||
while ($pz_row = $db->fetchByAssoc($pz_res)) {
|
||||
$pz = new EcmStockDocIn();
|
||||
$pz->retrieve($pz_row['parent_id']);
|
||||
if (!in_array($pz->stock_id, $stocks)) $stock_ok = false;
|
||||
$tmp['rel_doc'].= $pz->document_no.", ";
|
||||
$tmp['rel_doc_total'] += $pz->total;
|
||||
unset($pz);
|
||||
}
|
||||
} else continue;
|
||||
if ($stock_ok == false) continue;
|
||||
$tmp['lp'] = $c; $c++;
|
||||
$tmp['rel_doc'] = substr($tmp['rel_doc'],0,-2);
|
||||
//if ($inv->currency_id == 'PLN') $currency = 1; else $currency = $inv->currency_value_nbp;
|
||||
//TODO: check currency_value on documents
|
||||
$currency = 1;
|
||||
$tmp['brutto'] = $row['value'] * $currency;
|
||||
$tmp['netto'] = 0;
|
||||
$tmp['vat'] = 0;
|
||||
//prepare vats
|
||||
$dv_res = $db->query("SELECT DISTINCT vat_value as ecmvat_name, vat_id as value, netto, vat FROM documents_vat
|
||||
WHERE netto != 0 AND document_id = '".$row['id']."' ORDER BY ecmvat_name");
|
||||
$doc_vat = array();
|
||||
//insert zeros
|
||||
foreach ($vats as $k=>$v) {
|
||||
$doc_vat[$k][0] = 0;
|
||||
$doc_vat[$k][1] = 0;
|
||||
}
|
||||
while ($dv_row = $db->fetchByAssoc($dv_res)) {
|
||||
$doc_vat[$dv_row['ecmvat_name']][0] = round($dv_row['netto']*$currency,2);
|
||||
$doc_vat[$dv_row['ecmvat_name']][1] = round($dv_row['vat']*$currency,2);
|
||||
$tmp['netto'] += round($dv_row['netto']*$currency,2);
|
||||
$tmp['vat'] += round($dv_row['vat']*$currency,2);
|
||||
}
|
||||
$tmp['vats'] = $doc_vat;
|
||||
unset($doc_vat);
|
||||
$data[] = $tmp;
|
||||
unset($tmp);
|
||||
}
|
||||
|
||||
if ($group_accounts == true) {
|
||||
usort($data, "cmp");
|
||||
//creaate Accounts summary
|
||||
$tmp_data = array();
|
||||
$summary = array();
|
||||
$sum = array();
|
||||
$sum_vat = array();
|
||||
for ($i = 0; $i < sizeof($data); $i++) {
|
||||
$row = $data[$i];
|
||||
$row['lp'] = $i+1;
|
||||
$tmp_data[] = $row;
|
||||
if (array_key_exists("total_netto",$sum))
|
||||
$sum['total_netto'] += $row['netto']; else $sum['total_netto'] = $row['netto'];
|
||||
if (array_key_exists("total_brutto",$sum))
|
||||
$sum['total_brutto'] += $row['brutto']; else $sum['total_brutto'] = $row['brutto'];
|
||||
if (array_key_exists("total_vat",$sum))
|
||||
$sum['total_vat'] += $row['vat']; else $sum['total_vat'] = $row['vat'];
|
||||
if (array_key_exists("total_rel",$sum))
|
||||
$sum['total_rel'] += $row['rel_doc_total']; else $sum['total_rel'] = $row['rel_doc_total'];
|
||||
foreach ($row['vats'] as $k=>$v) {
|
||||
if (!array_key_exists($k,$sum_vat)) {
|
||||
$sum_vat[$k][0] = 0;
|
||||
$sum_vat[$k][1] = 0;
|
||||
}
|
||||
$sum_vat[$k][0] += $v[0];
|
||||
$sum_vat[$k][1] += $v[1];
|
||||
}
|
||||
if ($data[$i]['parent_id'] != $data[$i+1]['parent_id'] || $i == sizeof($data)) {
|
||||
//insert summary row
|
||||
$sum['is_summary'] = 1;
|
||||
$sum['index'] = $row['parent_index'];
|
||||
$sum['parent_info'] = 'Podsumowanie dla kontrahenta';
|
||||
$sum['vats'] = $sum_vat;
|
||||
$tmp_data[] = $sum;
|
||||
unset($sum); $sum = array();
|
||||
unset($sum_vat); $sum_vat = array();
|
||||
}
|
||||
}
|
||||
$data = $tmp_data;
|
||||
}
|
||||
|
||||
|
||||
$rop = 26; // rows on page
|
||||
$nop = ceil(sizeof($data)/$rop); // number of pages
|
||||
$pages_data = array_chunk($data, $rop);
|
||||
$pages = array();
|
||||
unset($data);
|
||||
$prev_page = array();
|
||||
$c = 1; //counter
|
||||
foreach ($pages_data as $data) {
|
||||
|
||||
$tmp = array();
|
||||
$tmp['site_netto'] = 0; $tmp['site_brutto'] = 0; $tmp['site_vat'] = 0; $tmp['site_pz'] = 0;
|
||||
$tmp['moved_netto'] = 0; $tmp['moved_brutto'] = 0; $tmp['moved_vat'] = 0; $tmp['moded_pz'] = 0;
|
||||
//prepare vats array
|
||||
$site_vats = array();
|
||||
$moved_vats = array();
|
||||
$total_vats = array();
|
||||
foreach ($vats as $k => $v) {
|
||||
$site_vats[$k][0] = 0;
|
||||
$site_vats[$k][1] = 0;
|
||||
$moved_vats[$k][0] = 0;
|
||||
$moved_vats[$k][1] = 0;
|
||||
$total_vats[$k][0] = 0;
|
||||
$total_vats[$k][1] = 0;
|
||||
}
|
||||
foreach ($data as $i) {
|
||||
if ($i['is_summary'] == 1) continue;
|
||||
$tmp['site_netto'] += $i['netto'];
|
||||
$tmp['site_brutto'] += $i['brutto'];
|
||||
$tmp['site_vat'] += $i['vat'];
|
||||
$tmp['site_pz'] += $i['rel_doc_total'];
|
||||
foreach ($i['vats'] as $k => $v) {
|
||||
$site_vats[$k][0] += $v[0];
|
||||
$site_vats[$k][1] += $v[1];
|
||||
}
|
||||
}
|
||||
if ($c!=1) { //not first page
|
||||
$tmp['moved_netto'] = $prev_page['total_netto'];
|
||||
$tmp['moved_brutto'] = $prev_page['total_brutto'];
|
||||
$tmp['moved_vat'] = $prev_page['total_vat'];
|
||||
$tmp['moved_pz'] = $prev_page['total_pz'];
|
||||
|
||||
foreach ($vats as $k=>$v) {
|
||||
$moved_vats[$k][0] += $prev_page['total_vats'][$k][0];
|
||||
$moved_vats[$k][1] += $prev_page['total_vats'][$k][1];
|
||||
}
|
||||
}
|
||||
$tmp['total_netto'] = $tmp['site_netto'] + $tmp['moved_netto'];
|
||||
$tmp['total_brutto'] = $tmp['site_brutto'] + $tmp['moved_brutto'];
|
||||
$tmp['total_vat'] = $tmp['site_vat'] + $tmp['moved_vat'];
|
||||
$tmp['total_pz'] = $tmp['site_pz'] + $tmp['moved_pz'];
|
||||
foreach ($vats as $k=>$v) {
|
||||
$total_vats[$k][0] += $site_vats[$k][0] + $moved_vats[$k][0];
|
||||
$total_vats[$k][1] += $site_vats[$k][1] + $moved_vats[$k][1];
|
||||
}
|
||||
//insert page data
|
||||
$tmp['rows'] = $data;
|
||||
$tmp['page_no'] = $c;
|
||||
$tmp['site_vats'] = $site_vats;
|
||||
$tmp['moved_vats'] = $moved_vats;
|
||||
$tmp['total_vats'] = $total_vats;
|
||||
|
||||
$pages[] = $tmp;
|
||||
$prev_page = $tmp;
|
||||
$c++;
|
||||
}
|
||||
|
||||
//create document and show it
|
||||
$ss_pdf = new Sugar_Smarty();
|
||||
$ss_pdf->assign("PAGES", $pages);
|
||||
$ss_pdf->assign("VATS", $vats);
|
||||
$ss_pdf->assign("vatsCount", $vatsCount);
|
||||
//header stuff
|
||||
$cur_date = new DateTime("now");
|
||||
$cur_date = $cur_date->format('d.m.Y H:m:s');
|
||||
$ss_pdf->assign("CUR_DATE", $cur_date);
|
||||
$ss_pdf->assign("DATE_FROM", $date_from);
|
||||
$ss_pdf->assign("DATE_TO", $date_to);
|
||||
$ss_pdf->assign("S_CATEGORY", $s_categories);
|
||||
$ss_pdf->assign("S_KIND", $s_kinds);
|
||||
$ss_pdf->assign("S_STOCK", $s_stocks);
|
||||
if($_REQUEST['to_xls']==1){
|
||||
$header=array();
|
||||
$header[]='nr dok.';
|
||||
$header[]='data wpływu';
|
||||
$header[]='data rejestru';
|
||||
$header[]='nr pz';
|
||||
$header[]='odbiorca - nip,nazwa,adres';
|
||||
$header[]='rodzaj';
|
||||
$header[]='zak .brutto';
|
||||
$header[]='zak. netto';
|
||||
$header[]='wartość pz';
|
||||
foreach ($vats as $val){
|
||||
$header[]='netto '.$val;
|
||||
$header[]='vat '.$val;
|
||||
}
|
||||
$header[]='vat razem';
|
||||
|
||||
$filename='modules/Home/Files/raport_ilosciowy_'.date('d_m-Y').'.csv';
|
||||
|
||||
$fp=fopen($filename,'w');
|
||||
foreach ($header as $k=>$v){
|
||||
|
||||
$header[$k]=iconv('UTF-8','windows-1250',$header[$k]);
|
||||
}
|
||||
fwrite($fp, implode(";",$header).PHP_EOL);
|
||||
|
||||
foreach ($pages[0]['rows'] as $key=>$val){
|
||||
|
||||
$line=array();
|
||||
$line[]='"=""'.preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['document_no']))).'"""';
|
||||
|
||||
$line[]=$val['publish_date'];
|
||||
$line[]=$val['register_date'];
|
||||
$line[]=$val['rel_doc'];
|
||||
$line[]=preg_replace("/[^A-ZłŁąĄęĘżŻ,:.źŹ%ćĆńŃśŚóÓa-z0-9\-\/]/",' ',preg_replace("/\r\n|\r|\n/",' ',html_entity_decode($val['parent_info'])));
|
||||
$line[]=$val['parent_type'];
|
||||
$line[]=str_replace(".",",",$val['brutto']);
|
||||
$line[]=str_replace(".",",",$val['netto']);
|
||||
$line[]=str_replace(".",",",$val['rel_doc_total']);
|
||||
foreach ($val['vats'] as $vi){
|
||||
$line[]=str_replace(".",",",$vi[0]);
|
||||
$line[]=str_replace(".",",",$vi[1]);
|
||||
}
|
||||
|
||||
$line[]=str_replace(".",",",$val['vat']);
|
||||
|
||||
foreach ($line as $k=>$v){
|
||||
$line[$k]=iconv('UTF-8','windows-1250',$line[$k]);;
|
||||
}
|
||||
fwrite($fp, implode(";",$line).PHP_EOL);
|
||||
}
|
||||
header("Location: ". $filename);
|
||||
}else {
|
||||
include_once ("modules/EcmSysInfos/EcmSysInfo.php");
|
||||
$EcmSysInfo = new EcmSysInfo();
|
||||
$ss_pdf->assign("COMPANY_NAME", $EcmSysInfo->getName());
|
||||
|
||||
$content = $ss_pdf->fetch ( 'modules/EcmReports/tpls/VatPurchasesPDF.tpl' );
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
$p = new mPDF ( '', 'A4', null, 'helvetica', 5, 5, 30, 5, 5, 5 );
|
||||
$p->writeHTML ($content) ;
|
||||
$p->setTitle ( "Rejestr zakupu VAT" );
|
||||
|
||||
$p->output("rej_zak.pdf", "I");
|
||||
}
|
||||
//helper
|
||||
function cmp($a, $b) {
|
||||
if ($a['parent_info'] == $b['parent_info']) {
|
||||
return ( $a['register_date'] > $b['register_date'] ) ? 1 : -1;
|
||||
}
|
||||
return ( $a['parent_info'] > $b['parent_info'] ) ? 1 : -1;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
global $app_list_strings;
|
||||
$p2=new mPDF('','A4', null, 'helvetica', 10,10,10,10,0,0);
|
||||
$i=0;
|
||||
$j=0;
|
||||
$db = $GLOBALS ['db'];
|
||||
$data = array ();
|
||||
//var_dump($_POST);
|
||||
foreach ($_POST as $klucz => $wartosc){
|
||||
|
||||
if($pos !== false){
|
||||
if($j%4==0){
|
||||
$p2->AddPage();
|
||||
}
|
||||
$j++;
|
||||
$tytul = "";
|
||||
$opis = "";
|
||||
$query = "SELECT
|
||||
d.document_date as docdate,
|
||||
d.document_name as docname,
|
||||
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
|
||||
documents d
|
||||
left join users u on u.id = d.created_by
|
||||
left join accounts a on d.parent_id = a.id
|
||||
WHERE
|
||||
d.id = '".$wartosc. "' AND d.deleted = 0";
|
||||
|
||||
/**
|
||||
* ************* GET DATA FROM DB********************
|
||||
*/
|
||||
echo $query;
|
||||
die();
|
||||
$rows = $db->query ( $query );
|
||||
while ( $r = $db->fetchByAssoc ( $rows ) ) {
|
||||
if($r['docname']!=NULL)
|
||||
$tytul = $tytul. "Nazwa dokumentu: ".$r['docname']."<br>";
|
||||
if($r['docdateentered']!=NULL)
|
||||
$tytul = $tytul."Data wprowadzenia: ".$r['docdateentered']."<br>";
|
||||
if($r['docdate']!=NULL)
|
||||
$tytul = $tytul."Data dokumentu: ".$r['docdate']."<br>";
|
||||
if($r ['doccategory']!=NULL)
|
||||
$tytul = $tytul."Kategoria: ".$app_list_strings['document_category_dom'][$r ['doccategory']]."<br>";
|
||||
if($r['docwartosc']!=NULL)
|
||||
$tytul = $tytul."Wartość: ".number_format($r['docwartosc'], 2, ",", ".")."<br>";
|
||||
if($r['username']!=NULL && $r['userlastname']!=NULL)
|
||||
$tytul = $tytul."Wprowadził: ".$r['username']." ".$r['userlastname']."<br>";
|
||||
if($r['docdes']!=NULL)
|
||||
$tytul = $tytul."Opis dokumentu: ".$r['docdes']."<br>";
|
||||
|
||||
// Wczytywanie raportów
|
||||
$queryraport = "
|
||||
SELECT
|
||||
CONCAT(u.first_name, ' ', u.last_name) AS name,
|
||||
d.accepted AS accepted,
|
||||
d.accepted_description AS accepteddes
|
||||
FROM
|
||||
documents_user d
|
||||
left join users u on u.id = d.user_id
|
||||
WHERE
|
||||
d.document_id = '".$wartosc."'";
|
||||
$tmp = $db->query ( $queryraport );
|
||||
if($tmp->num_rows == 0){
|
||||
$opisy = "";
|
||||
}else{
|
||||
$opisy = "<table style='border: 1px solid black; padding: 3px;'>
|
||||
<tr>
|
||||
<th style='border: 1px solid black; padding: 3px;'>Użytkownik</th>
|
||||
<th style='border: 1px solid black; padding: 3px;'>Status</th>
|
||||
<th style='border: 1px solid black; padding: 3px;'>Opis</th>
|
||||
</tr>";
|
||||
while($tmp2 = $db->fetchByAssoc($tmp)){
|
||||
$opisy = $opisy . "<tr>";
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>".$tmp2['name']."</td>";
|
||||
if($tmp2['accepted']==0){
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>Oczekuje</td>";
|
||||
}elseif($tmp2['accepted']==1){
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>Zaakceptowano</td>";
|
||||
}elseif($tmp2['accepted']==2){
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>Odrzucono</td>";
|
||||
}
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>".str_replace("XVZC","<br>",$tmp2['accepteddes'])."</td>";
|
||||
$opisy = $opisy ."</tr>";
|
||||
};
|
||||
$opisy = $opisy . "</table>";
|
||||
}
|
||||
}
|
||||
$p2->WriteHTML($tytul . $opisy . "<hr>");
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
var_dump($opisy);
|
||||
echo $tytul . $opisy ;
|
||||
//$p2->Output ();
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
include_once ("include/MPDF57/mpdf.php");
|
||||
global $app_list_strings;
|
||||
$p2=new mPDF('','A4', null, 'helvetica', 10,10,10,10,0,0);
|
||||
$i=0;
|
||||
$j=0;
|
||||
$db = $GLOBALS ['db'];
|
||||
$data = array ();
|
||||
//var_dump($_POST);
|
||||
foreach ($_POST as $klucz => $wartosc){
|
||||
$pos = strpos($klucz, 'box_');
|
||||
if($pos !== false){
|
||||
if($j%4==0){
|
||||
$p2->AddPage();
|
||||
}
|
||||
$j++;
|
||||
$tytul = "";
|
||||
$opis = "";
|
||||
$query = "SELECT
|
||||
d.document_date as docdate,
|
||||
d.document_name as docname,
|
||||
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
|
||||
documents d
|
||||
left join users u on u.id = d.created_by
|
||||
left join accounts a on d.parent_id = a.id
|
||||
WHERE
|
||||
d.id = '".$wartosc. "' AND d.deleted = 0";
|
||||
|
||||
/**
|
||||
* ************* GET DATA FROM DB********************
|
||||
*/
|
||||
$rows = $db->query ( $query );
|
||||
while ( $r = $db->fetchByAssoc ( $rows ) ) {
|
||||
if($r['docname']!=NULL)
|
||||
$tytul = $tytul. "Nazwa dokumentu: ".$r['docname']."<br>";
|
||||
if($r['docdateentered']!=NULL)
|
||||
$tytul = $tytul."Data wprowadzenia: ".$r['docdateentered']."<br>";
|
||||
if($r['docdate']!=NULL)
|
||||
$tytul = $tytul."Data dokumentu: ".$r['docdate']."<br>";
|
||||
if($r ['doccategory']!=NULL)
|
||||
$tytul = $tytul."Kategoria: ".$app_list_strings['document_category_dom'][$r ['doccategory']]."<br>";
|
||||
if($r['docwartosc']!=NULL)
|
||||
$tytul = $tytul."Wartość: ".number_format($r['docwartosc'], 2, ",", ".")."<br>";
|
||||
if($r['username']!=NULL && $r['userlastname']!=NULL)
|
||||
$tytul = $tytul."Wprowadził: ".$r['username']." ".$r['userlastname']."<br>";
|
||||
if($r['docdes']!=NULL)
|
||||
$tytul = $tytul."Opis dokumentu: ".$r['docdes']."<br>";
|
||||
|
||||
// Wczytywanie raportów
|
||||
$queryraport = "
|
||||
SELECT
|
||||
CONCAT(u.first_name, ' ', u.last_name) AS name,
|
||||
d.accepted AS accepted,
|
||||
d.accepted_description AS accepteddes
|
||||
FROM
|
||||
documents_user d
|
||||
left join users u on u.id = d.user_id
|
||||
WHERE
|
||||
d.document_id = '".$wartosc."'";
|
||||
$tmp = $db->query ( $queryraport );
|
||||
if($tmp->num_rows == 0){
|
||||
$opisy = "";
|
||||
}else{
|
||||
$opisy = "<table style='border: 1px solid black; padding: 3px;'>
|
||||
<tr>
|
||||
<th style='border: 1px solid black; padding: 3px;'>Użytkownik</th>
|
||||
<th style='border: 1px solid black; padding: 3px;'>Status</th>
|
||||
<th style='border: 1px solid black; padding: 3px;'>Opis</th>
|
||||
</tr>";
|
||||
while($tmp2 = $db->fetchByAssoc($tmp)){
|
||||
$opisy = $opisy . "<tr>";
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>".$tmp2['name']."</td>";
|
||||
if($tmp2['accepted']==0){
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>Oczekuje</td>";
|
||||
}elseif($tmp2['accepted']==1){
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>Zaakceptowano</td>";
|
||||
}elseif($tmp2['accepted']==2){
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>Odrzucono</td>";
|
||||
}
|
||||
$opisy = $opisy ."<td style='border: 1px solid black; padding: 3px;'>".str_replace("XVZC","<br>",$tmp2['accepteddes'])."</td>";
|
||||
$opisy = $opisy ."</tr>";
|
||||
};
|
||||
$opisy = $opisy . "</table>";
|
||||
}
|
||||
}
|
||||
$p2->WriteHTML($tytul . $opisy . "<hr>");
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$p2->Output ();
|
||||
?>
|
||||
88
modules/var/www/html/system/modules/EcmReports/vardefs.php
Normal file
88
modules/var/www/html/system/modules/EcmReports/vardefs.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
$dictionary['EcmReport']=array(
|
||||
'table'=>'ecmreports',
|
||||
'audited'=>false,
|
||||
'comment'=>'EcmReports',
|
||||
'duplicate_merge'=>true ,
|
||||
'unified_search'=>true,
|
||||
'fields'=>array(
|
||||
'name'=>array(
|
||||
'name'=>'name',
|
||||
'vname'=>'LBL_NAME',
|
||||
'type'=>'varchar',
|
||||
'len'=>'255',
|
||||
),
|
||||
),
|
||||
'indices'=>array(
|
||||
array('name'=>'idx_ecmreport_id_del','type'=>'index','fields'=>array('id','deleted')),
|
||||
array('name'=>'idx_ecmreport_assigned_del','type'=>'index','fields'=>array( 'deleted', 'assigned_user_id')),
|
||||
),
|
||||
'relationships'=>array(
|
||||
'ecmreports_assigned_user'=>array(
|
||||
'lhs_module'=>'Users',
|
||||
'lhs_table'=>'users',
|
||||
'lhs_key'=>'id',
|
||||
'rhs_module'=>'EcmReports',
|
||||
'rhs_table'=>'ecmreports',
|
||||
'rhs_key'=>'assigned_user_id',
|
||||
'relationship_type'=>'one-to-many'
|
||||
),
|
||||
'ecmreports_modified_user'=>array(
|
||||
'lhs_module'=>'Users',
|
||||
'lhs_table'=>'users',
|
||||
'lhs_key'=>'id',
|
||||
'rhs_module'=>'EcmReports',
|
||||
'rhs_table'=>'ecmreports',
|
||||
'rhs_key'=>'modified_user_id',
|
||||
'relationship_type'=>'one-to-many'
|
||||
),
|
||||
'ecmreports_created_by'=>array(
|
||||
'lhs_module'=>'Users',
|
||||
'lhs_table'=>'users',
|
||||
'lhs_key'=>'id',
|
||||
'rhs_module'=>'EcmReports',
|
||||
'rhs_table'=>'ecmreports',
|
||||
'rhs_key'=>'created_by',
|
||||
'relationship_type'=>'one-to-many'
|
||||
)
|
||||
),
|
||||
'optimistic_locking'=>true,
|
||||
);
|
||||
require_once('include/SugarObjects/VardefManager.php');
|
||||
VardefManager::createVardef('EcmReports','EcmReport', array('default','assignable'));
|
||||
?>
|
||||
Reference in New Issue
Block a user