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="";$se=""; if($today_saldo<0)$ss="";$se=""; $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 = ''; $push_register = ''; } 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').'
'; 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; } ?>