Files
crm.twinpol.com/modules/Accounts/views/view.detail.php
2025-05-12 15:44:39 +00:00

260 lines
9.8 KiB
PHP

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero 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 Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero 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 Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero 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/MVC/View/views/view.detail.php');
class AccountsViewDetail extends ViewDetail {
function AccountsViewDetail(){
parent::ViewDetail();
}
/**
* display
* Override the display method to support customization for the buttons that display
* a popup and allow you to copy the account's address into the selected contacts.
* The custom_code_billing and custom_code_register Smarty variables are found in
* include/SugarFields/Fields/Address/DetailView.tpl (default). If it's a English U.S.
* locale then it'll use file include/SugarFields/Fields/Address/en_us.DetailView.tpl.
*/
function display(){
if(empty($this->bean->id)){
global $app_strings;
sugar_die($app_strings['ERROR_NO_RECORD']);
}
global $mod_strings;
//add mz
$pl = $this->bean->showPositions();
$pl2 = $this->bean->showPositions2();
$pl3 = $this->bean->showPositions3();
$pl4 = $this->bean->showPositions4();
$ws = $this->bean->ShowWebSitesList();
$ws2 = $this->bean->ShowTelephonesList();
$this->ss->assign('WEBSITES_LIST', $ws);
$this->ss->assign('TELEPHONES_LIST', $ws2);
$this->ss->assign('POSITIONS', $pl);
$this->ss->assign('POSITIONS2', $pl2);
$this->ss->assign('POSITIONS3', $pl3);
$this->ss->assign('POSITIONS4', $pl4);
$this->ss->assign('LBL_PHONE', $app_strings['LBL_PHONE']);
$this->ss->assign('LBL_FAX', $app_strings['LBL_FAX']);
$this->ss->assign('LBL_SAVE_TO_GOOGLE', $mod_strings['LBL_SAVE_TO_GOOGLE']);
$datachart = AnalysisProductSale($this->bean->id);
//var_dump($data);
$rows = array();
foreach ($datachart 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'];
}
$this->ss->assign("DATACHART", $datachart);
$this->ss->assign("ROWS", $rows);
//get salda ;)
$saldo = $this->bean->getSalda(8);
$today_saldo = $this->bean->getSalda(9);
//end get salda
if($saldo<0)$ss="<span style='color:red'>";$se="</span>";
if($today_saldo<0)$ss="<span style='color:red'>";$se="</span>";
$this->ss->assign('saldo', $ss.format_number($saldo).$se);
$this->ss->assign('today_saldo', $ss.format_number($today_saldo).$se);
//end mz
$this->dv->process();
global $mod_strings;
if(ACLController::checkAccess('Contacts', 'edit', true)) {
$push_billing = '<span class="id-ff"><button class="button btn_copy" title="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_LABEL'] .
'" type="button" onclick=\'open_contact_popup("Contacts", 600, 600, "&account_name=' .
urlencode($this->bean->name) . '&html=change_address' .
'&primary_address_street=' . str_replace(array("\rn", "\r", "\n"), array('','','<br>'), urlencode($this->bean->billing_address_street)) .
'&primary_address_city=' . $this->bean->billing_address_city .
'&primary_address_state=' . $this->bean->billing_address_state .
'&primary_address_postalcode=' . $this->bean->billing_address_postalcode .
'&primary_address_country=' . $this->bean->billing_address_country .
'", true, false);\' value="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_TITLE']. '">'.
SugarThemeRegistry::current()->getImage("id-ff-copy","",null,null,'.png',$mod_strings["LBL_COPY"]).
'</button></span>';
$push_register = '<span class="id-ff"><button class="button btn_copy" title="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_LABEL'] .
'" type="button" onclick=\'open_contact_popup("Contacts", 600, 600, "&account_name=' .
urlencode($this->bean->name) . '&html=change_address' .
'&primary_address_street=' . str_replace(array("\rn", "\r", "\n"), array('','','<br>'), urlencode($this->bean->register_address_street)) .
'&primary_address_city=' . $this->bean->register_address_city .
'&primary_address_state=' . $this->bean->register_address_state .
'&primary_address_postalcode=' . $this->bean->register_address_postalcode .
'&primary_address_country=' . $this->bean->register_address_country .
'", true, false);\' value="' . $mod_strings['LBL_PUSH_CONTACTS_BUTTON_TITLE'] . '">'.
SugarThemeRegistry::current()->getImage("id-ff-copy",'',null,null,'.png',$mod_strings['LBL_COPY']).
'</button></span>';
} else {
$push_billing = '';
$push_register = '';
}
$this->ss->assign("custom_code_billing", $push_billing);
$this->ss->assign("custom_code_register", $push_register);
if(empty($this->bean->id)){
global $app_strings;
sugar_die($app_strings['ERROR_NO_RECORD']);
}
echo $this->dv->display();
}
}
function AnalysisProductSale($account_id) {
global $db;
try {
$tmp = new DateTime(date('Y-m-31'));
$tmp2 = new DateTime(date('Y-m-01'));
$tmp2->sub(new DateInterval('P11M'));
$register_date_to = $tmp->format('Y-m-d');
$register_date_from = $tmp2->format('Y-m-d');
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
$query = "
SELECT
p.id,
p.old_ecminvoiceoutitem_id,
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
i.canceled=0
AND i.deleted=0
AND i.register_date <= '" . $register_date_to . "'
AND i.register_date >= '" . $register_date_from . "'
AND p.ecminvoiceout_id = i.id
AND i.parent_id='" . $account_id ."'
ORDER BY
i.register_date;" ;
//die(1);
//echo $query;
//echo $query;
$result = $db->query($query);
$result2 = $db->query($query);
if ($result2->num_rows > 0) {
while ($row = $result2->fetch_assoc()) {
$tmparray[$row['id']] = $row;
}
}
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($tmparray[$row['old_ecminvoiceoutitem_id']]['price_purchase'] * $row['quantity_corrected'] ,2);
$return[substr($row['register_date'], 0, 7)]['total_netto'] += $row['total_netto_corrected']* $currency;
}
}
} else {
return NULL;
}
global $current_user;
if(count($return)<12){
try {
$currentDate = new DateTime(date('Y-m-01'));
$date = new DateTime(date('Y-m-01'));
$date->sub(new DateInterval('P11M'));
$register_date_fill = $date->format('Y-m');
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
while(count($return)<12){
// echo $date->format('Y-m').'<br>';
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;
}
?>