Link_ID ) { $this->Link_ID = mysqli_connect($this->Host, $this->User, $this->Password, $this->Database); if (!$this->Link_ID) { $this->halt("Link-ID == false, pconnect failed"); } else debug (0, "ALLORA") ; // if (!mysqli_select_db($this->Database,$this->Link_ID)) { // $this->halt("cannot use database ".$this->Database . " " . $this->Link_ID); // } } } function query($Query_String) { debug (0, $Query_String) ; $this->connect() ; $this->Query_ID = mysqli_query($this->Link_ID, $Query_String) ; $this->Row = 0; $this->Errno = mysqli_errno($this->Link_ID); $this->Error = mysqli_error($this->Link_ID); if (!$this->Query_ID) { $this->halt("Invalid SQL: ".$Query_String); } return $this->Query_ID; } function eseguiquery($query) { return $this->query($query); } function RecuperaDati($query) { $arr_val = array() ; $num_rows = 0 ; $i = 0 ; $this->connect(); // $this->Query_ID = mysql_query($query, $this->Link_ID); $this->Query_ID = mysqli_query($this->Link_ID, $query); $this->Row = 0; $this->Errno = mysqli_errno($this->Link_ID); $this->Error = mysqli_error($this->Link_ID); if (!$this->Query_ID) { $this->halt("Invalid SQL: ".$Query_String); return array(-1, array()) ; } while ($i < mysqli_num_fields($this->Query_ID)) { $meta = mysqli_fetch_field($this->Query_ID); if ($meta) $arr_val[$meta->name] = array() ; $i++; } while($row = mysqli_fetch_array($this->Query_ID, MYSQLI_ASSOC) ) { foreach($row as $key => $value) $arr_val[$key][] = $value ; $num_rows ++ ; } return array($num_rows, $arr_val) ; } function checkTable($table) { $query = "select * from $table" ; $this->connect(); $this->Query_ID = mysql_query($query, $this->Link_ID); if (!$this->Query_ID) return 0 ; else return 1 ; } function next_record() { $this->Record = mysqli_fetch_array($this->Query_ID); $this->Row += 1; $this->Errno = mysqli_errno($this->Link_ID); $this->Error = mysqli_error($this->Link_ID); debug (0, "NEXREC ". $this->Row) ; $stat = is_array($this->Record); if (!$stat && $this->Auto_free) { mysql_free_result($this->Query_ID); $this->Query_ID = 0; } return $stat; } function seek($pos) { $status = mysql_data_seek($this->Query_ID, $pos); if ($status) $this->Row = $pos; return; } function metadata($table) { $count = 0; $id = 0; $res = array(); $this->connect(); $id = @mysql_list_fields($this->Database, $table); if ($id < 0) { $this->Errno = mysql_errno(); $this->Error = mysql_error(); $this->halt("Metadata query failed."); } $count = mysql_num_fields($id); for ($i=0; $i<$count; $i++) { $res[$i]["table"] = mysql_field_table ($id, $i); $res[$i]["name"] = mysql_field_name ($id, $i); $res[$i]["type"] = mysql_field_type ($id, $i); $res[$i]["len"] = mysql_field_len ($id, $i); $res[$i]["flags"] = mysql_field_flags ($id, $i); $res["meta"][$res[$i]["name"]] = $i; $res["num_fields"]= $count; } mysql_free_result($id); return $res; } function affected_rows() { return mysql_affected_rows($this->Link_ID); } function num_rows() { debug (0, "NR ") ; return mysqli_num_rows($this->Query_ID) ; } function num_fields() { return mysql_num_fields($this->Query_ID); } function nf() { return $this->num_rows(); } function np() { print $this->num_rows(); } function f($Name) { return $this->Record[$Name]; } function p($Name) { print $this->Record[$Name]; } function halt($msg) { printf("Database error: %s
\n", $msg); printf("MySQL Error: %s (%s)
\n", $this->Errno, $this->Error); die("Session halted."); } } // $db_azienda = "dali" ; $db_azienda = "dali2022" ; $idsarzi = 121 ; $dirordini = "C:\\php_app\\GestioneAzienda\\ordini\\" ; $dirlistini = "C:\\php_app\\GestioneAzienda\\fornitori\\listini\\" ; $dirtemplate = "C:\\php_app\\GestioneAzienda\\template\\" ; /*************************************************************** * Gestione delle tabelle in base all'anno di gestione ****************************************************************/ // $anno="2003" ; $tagenti = "agenti_$anno" ; $tclienti = "clienti_$anno" ; $ttipologie = "tipologie_$anno" ; $tfornitori = "fornitori_$anno" ; $taziende = "aziende_$anno" ; $tordini = "ordini_$anno" ; $tageforper = "ageforper_$anno" ; $tdettagli = "dettagli_$anno" ; $tpagamenti = "pagamenti_$anno" ; $tprodotti = "prodotti_$anno" ; $tcategorie = "categorie_$anno" ; $tprovvigioni = "provvigioni_$anno" ; $tprovvigioniAgenti = "provvigioniAgenti_$anno" ; $tsarzi = "sarzi_$anno" ; $tiva = "iva_$anno" ; $tprogclienti = "progclienti_$anno" ; $tprogrammazione = "programmazione_$anno" ; $tscontomerce = "scontomerce_$anno" ; $tformato = "formato" ; $tparametri = "ParametriGenerali_$anno" ; $ttarget = "Target_$anno" ; $trelprodottotarget = "relprodottitarget_$anno" ; $tAmmontareVariOrdini = "AmmontareVariOrdini_$anno" ; /******************************************************************** * mi creo un array con tutte le tabelle dell'archivio. * Quest'array mi servir� in fase di inizializzazione del nuovo anno ********************************************************************/ $arAllTable[] = array("tabella" => "ageforper", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "agenti", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "AmmontareVariOrdini", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "aziende", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "categorie", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "clienti", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "dettagli", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "fornitori", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "iva", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "ordini", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "pagamenti", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "ParametriGenerali", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "prodotti", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "progclienti", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "programmazione", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "provvigioniagenti", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "provvigioni", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "relprodottitarget", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "sarzi", "copiadati" => "1") ; $arAllTable[] = array("tabella" => "scontomerce", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "target", "copiadati" => "0") ; $arAllTable[] = array("tabella" => "tipologie", "copiadati" => "1") ; $arrMesi = array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre") ; function Debug($display, $str) { if ($display == 1) echo ("DEBUG: $str
") ; elseif ($display == 2) { echo ("DEBUG: $str
") ; exit ; } } function DebugPre($display, $str) { if ($display == 1) echo ("
DEBUG: $str
") ; elseif ($display == 2) { echo ("
DEBUG: $str
") ; exit ; } } function ItaDate($str) { $r = preg_match ("/([0-9]{4})[-\/]([0-9]{2})[-\/]([0-9]{2})/", $str, $reg_str) ; $str = sprintf("%s/%s/%s", $reg_str[3], $reg_str[2], $reg_str[1]) ; if ($str != "00/00/0000" and $str != "//") return $str ; else return "" ; } /* OLD VERSION function ItaDate($str) { preg_match ("/([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})", $str, $reg_str) ; print_r($reg_str) ; $str = sprintf("%s/%s/%s", $reg_str[3], $reg_str[2], $reg_str[1]) ; if ($str != "00/00/0000" and $str != "//") return $str ; else return "" ; } */ function ItaDate_2($str) { preg_match ("/([0-9]{4})\/([0-9]{1,2})\/([0-9]{1,2})", $str, $reg_str) ; $str = sprintf("%s-%s-%s", $reg_str[3], $reg_str[2], $reg_str[1]) ; if ($str != "00-00-0000" and $str != "--") return $str ; else return "" ; } function MySqlDate($str) { preg_match ("/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/", $str, $res) ; $str = sprintf("%s/%s/%s", $res[3],$res[2],$res[1]) ; if ($str != "0000/00/00" and $str != "//") return $str ; else return '' ; } function MySqlDate_2($str) { preg_match ("/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/", $str, $res) ; $str = sprintf("%s-%s-%s", $res[3],$res[2],$res[1]) ; if ($str != "0000-00-00" and $str != "//") return $str ; else return '' ; } function SiNo($str) { if ($str == "0") return "No" ; else return "Si" ; } function nfl($str) { /******************************************************* * formatta i numeri per le lire * Esempio : 1.456.000 *********************************************************/ return number_format($str, 0, "", ".") ; // return number_format($str, 2) ; } function nfe($str) { /******************************************************* * formatta i numeri per l'euro * Esempio : 1.456.000,32 *********************************************************/ $str = floatval($str) ; // prima return number_format($str, 2, ",", ".") ; // poi return number_format($str, 2, ",", "") ; } function nfeExt($str) { /******************************************************* * formatta i numeri per l'euro fino a 5 cifre decimali * Esempio : 1.456.000,32 *********************************************************/ return number_format($str, 5, ",", ".") ; } function nfp($str) { /******************************************************* * formatta i numeri con le virgole e viene utilizzata * nella visualizzazione delle percentuali * Esempio : 3,75% *********************************************************/ $str = floatval($str) ; return number_format($str, 2, ",", ".") ; } function NumToSql($str) { /************************************************* * Trasforma un numero con la virgola in formato * italiano del tipo 2.000,45 in un numero in formato * Db del tipo 2000.45 ***************************************************/ $str = str_replace("\.", "", $str) ; debug (0, "TMP = $str") ; $str = str_replace(",", ".", $str) ; return $str ; } function nflno($str) { // Visualizza un numero senza decimali e senza simboli delle // migliaia return number_format($str, 0, "", "") ; } function nfeNoDot($str) { /*********************************************** * Formatta un numero da es. 1200.00 a 1200,00 ***********************************************/ return number_format($str, 2, ',', ''); } /** * Converts a date to number of days since a * distant unspecified epoch. * * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * * @access public * * @return integer number of days */ function dateToDays($day,$month,$year) { $century = substr($year,0,2); $year = substr($year,2,2); if($month > 2) $month -= 3; else { $month += 9; if($year) $year--; else { $year = 99; $century --; } } return ( floor((146097 * $century) / 4 ) + floor((1461 * $year) / 4 ) + floor((153 * $month + 2) / 5 ) + $day + 1721119); } // end func dateToDays /** * Returns number of days between two given dates. * * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * * @return int absolute number of days between dates, * -1 if there is an error. */ function dateDiff($day1,$month1,$year1,$day2,$month2,$year2) { // if(!Date_Calc::isValidDate($day1,$month1,$year1)) // return -1; // if(!Date_Calc::isValidDate($day2,$month2,$year2)) // return -1; return (abs((dateToDays($day1,$month1,$year1)) - dateToDays($day2,$month2,$year2))); } // end func dateDiff class FC_SQL extends DBbase_Sql { // var $Host = "localhost"; var $Host = "127.0.0.1"; var $Database = "dali2022"; var $User = "root"; // var $Password = "root"; var $Password = ""; function free_result() { return @mysql_free_result($this->Query_ID); } function rollback() { return 1; } function commit() { return 1; } function autocommit($onezero) { return 1; } function insert_id($col="",$tbl="",$qual="") { return mysql_insert_id($this->Query_ID); } } class FC_SQL_FAB extends DBbase_Sql { // var $Host = "localhost"; var $Host = "127.0.0.1"; var $Database = "dali2022"; var $User = "root"; // var $Password = "root"; var $Password = ""; function free_result() { return @mysql_free_result($this->Query_ID); } function rollback() { return 1; } function commit() { return 1; } function autocommit($onezero) { return 1; } function insert_id($col="",$tbl="",$qual="") { return mysql_insert_id($this->Query_ID); } } function CalcolaScontoProdotto($totale, $sconto) { $val = preg_split("/\+/", $sconto, -1, PREG_SPLIT_NO_EMPTY) ; for($i=0; $iconnect() ; function RecuperaPreProProdotto($tipo, $nome) { global $tprodotti ; $db = new FC_SQL ; $id = 0 ; $nome_ret = "" ; if ($tipo == 0) // prossimo { $where = " Nome > '$nome' " ; $ord = "ASC" ; } else // precedente { $where = " Nome < '$nome' " ; $ord = "DESC" ; } $query = " select * from $tprodotti where $where order by Nome $ord limit 1 " ; $db->query($query) ; while ($db->next_record()) { $nome_ret = $db->f("Nome") ; $id = $db->f("IdProdotti") ; } return array($id, $nome_ret) ; } function ControllaLogin($login, $passwd) { $db = new FC_SQL ; $query = " select * from user where login = '$login' and password = '$passwd' " ; $db->query($query) ; debug (0, "QQ ") ; if ($db->num_rows() == 1) { debug (0, $passwd) ; while ($db->next_record()) $_SESSION['profilo'] = $db->f("profilo") ; return true ; } else { return false ; } } set_time_limit(0) ; function RecuperaParametriGenerali($arrParGen, $tparametri) { $db = new FC_SQL ; $query = " select * from parametrigenerali " ; list($n, $d) = $db->RecuperaDati($query) ; // Parametri Agenzia $arrParGen['NomeAgenzia'] = $d['NomeAgenzia'][0] ; $arrParGen['IndirizzoAgenzia'] = $d['IndirizzoAgenzia'][0] ; $arrParGen['TelefonoAgenzia'] = $d['TelefonoAgenzia'][0] ; $arrParGen['FaxAgenzia'] = $d['FaxAgenzia'][0] ; $arrParGen['PartitaIvaAgenzia'] = $d['PartitaIvaAgenzia'][0] ; $arrParGen['CodiceFiscaleAgenzia'] = $d['CodiceFiscaleAgenzia'][0] ; $arrParGen['MailAgenzia'] = $d['MailAgenzia'][0] ; // Parametri Provvigioni $arrParGen['PercEnasarcoVis'] = $d['PercEnasarco'][0] ; $arrParGen['PercEnasarco'] = NumToSql($d['PercEnasarco'][0]) ; $arrParGen['PercRitenutaVis'] = $d['PercRitenuta'][0] ; $arrParGen['PercRitenuta'] = NumToSql($d['PercRitenuta'][0]) ; $arrParGen['MaxAgenteMono'] = $d['MaxAgenteMono'][0] ; $arrParGen['MaxAgentePluri'] = $d['MaxAgentePluri'][0] ; // Parametri Customer Pyramid $arrParGen['PercVendCP'] = $d['PercVendCP'][0] ; $arrParGen['PercProdCP'] = $d['PercProdCP'][0] ; $arrParGen['PercPagCP'] = $d['PercPagCP'][0] ; $arrParGen['NumOrdCP'] = $d['NumOrdCP'][0] ; // Parametri Vari $arrParGen['MaxProdottiPerOrdine'] = $d['MaxProdottiPerOrdine'][0] ; $arrParGen['GioMesFine1Periodo'] = $d['GioMesFine1Periodo'][0] ; $arrParGen['IvaPredefinito'] = $d['IvaPredefinito'][0] ; return $arrParGen ; } function StampaStr($str) { if ($str == "") $str = " " ; return $str ; } // include "operazioni.php" ; /* NON SERVE PIU ? require_once( 'class.ConfigMagik.php'); $Config = new ConfigMagik( 'public_par.ini', true, true); $Config->SYNCHRONIZE = false; // $percena = $Config->get('p_percena', 'provvigioni') ; // $percrit = $Config->get('p_percrit', 'provvigioni') ; $azienda_gest = $Config->get('p_azienda_gest', 'azienda') ; $ordiniperpagina = $Config->get('p_ordiniperpagina', 'vari') ; $inviaperpagina = $Config->get('p_inviaperpagina', 'vari') ; $prodottiperpagina = $Config->get('p_prodottiperpagina', 'vari') ; $sarziperpagina = $Config->get('p_sarziperpagina', 'vari') ; $clientiperpagina = $Config->get('p_clientiperpagina', 'vari') ; // $dataperiodo = $Config->get('p_dataperiodo', 'vari') ; // list($gdp, $mdp) = split("/", $dataperiodo) ; // $dataperiodo = sprintf("%04d-%02d-%02d", Date("Y"), $mdp, $gdp) ; $cp_venduto = $Config->get('p_venduto', 'cust_pyr') / 100 ; $cp_prodotti = $Config->get('p_prodotti', 'cust_pyr') / 100; $cp_pagamenti = $Config->get('p_pagamenti', 'cust_pyr') / 100 ; $cp_nordini = $Config->get('p_nordini', 'cust_pyr') ; */ function CreaArrayAmmontareOrdini() { /*** * restituisce due array: il primo ha come chiave l'id dell'ordine e come valore l'ammontare dello stesso -- senza IVA * ma considerando lo sconto prodotto; * il secondo contiene per ogni ordine l'ammontare considerando sia lo sconto prodotto che l'iva * VERSIONE 3.0 READY ***/ $db = new FC_SQL ; global $anno ; global $tdettagli ; global $tprodotti ; global $tsarzi ; global $tiva ; /* * Ho eliminato la tabella di sarzi, per cui la query diventa * Funzione già modificata per la versione 3.0 */ $q = " select D.IdOrdine as OrdineId, D.*, P.PrezzoUnitario, (D.NumCartoni * D.ConfezioniDa * P.PrezzoUnitario) as ImpParz, D.ScontoPrd, I.Aliquota from dettagli D inner join prodotti P on P.idprodotti = D.idprodotto inner join iva I on I.idIva = P.IdIvaPrd where P.Anno = $anno and D.Anno = $anno order by IdOrdine " ; list($n, $d) = $db->RecuperaDati($q) ; // print_r($d) ; exit ; for ($i=0; $i<$n; $i++) { if ($d['PrezzoForzato'][$i] > 0) $impParz = $d['NumCartoni'][$i] * $d['ConfezioniDa'][$i] * $d['PrezzoForzato'][$i] ; else $impParz = $d['NumCartoni'][$i] * $d['ConfezioniDa'][$i] * $d['PrezzoUnitario'][$i] ; // $impParz = $d['ImpParz'][$i] ; if ($d['ScontoPrd'][$i] != "") $impParz = CalcolaScontoProdotto($impParz, $d['ScontoPrd'][$i]) ; // Prima: $impIva = ($impParz * $d["Aliquota"][$i] / 100) ; $impIva = ($impParz * $d["Iva"][$i] / 100) ; $arrImpOrdini[$d['IdOrdine'][$i]]['SenzaIva'] += $impParz ; $arrImpOrdini[$d['IdOrdine'][$i]]['ConIva'] += $impParz + $impIva ; } return $arrImpOrdini ; } /***************************************************************** * 15.11.2021. Modifiche 3.0 * Se eventualmente serve considerare un anno in particolare, allora * bisogna passarlo cone paramentro -- D A F A R E ? --- *****************************************************************/ function CreaArrayAmmontareVariOrdini() { global $anno ; $db = new FC_SQL ; global $tAmmontareVariOrdini ; $query = " select AVO.* from AmmontareVariOrdini AVO where AVO.Anno = $anno order by AVO.IdOrdine " ; list($n, $d) = $db->RecuperaDati($query) ; return $d ; } function EsisteTabella($table) { $db = new FC_SQL ; return ($db->checkTable($table)) ; } /******************************************************* * Prende una data in formato dd/mm/YYYY e gli aggiunge * un certo numero di giorni *******************************************************/ function CalcolaDataScadenza($givendate,$day,$mth=0,$yr=0) { if ($day != 0 and $day != 999) { $cd = strtotime($givendate); $newdate = date('Y-m-d', mktime(date('h',$cd), date('i',$cd), date('s',$cd), date('m',$cd)+$mth, date('d',$cd)+$day, date('Y',$cd)+$yr)) ; } else $newdate = $givendate ; return $newdate; } function PreparaStringaPerPDF($str) { $retStr = str_replace("�", "e'", $str) ; $retStr = str_replace("�", "e'", $retStr) ; $retStr = str_replace("�", "a'", $retStr) ; $retStr = str_replace("�", "i'", $retStr) ; $retStr = str_replace("�", "o'", $retStr) ; $retStr = str_replace("�", "u'", $retStr) ; return $retStr ; } function CalcolaQualeIva($data) { $dataCambioIva1 = "2011-09-19" ; $dataCambioIva2 = "2013-09-30" ; if ($data <= $dataCambioIva1 ) return 20 ; else if ($data <= $dataCambioIva2 ) return 21 ; else return 22 ; } $arrParGen = array() ; $arrParGen = RecuperaParametriGenerali($arrParGen, $tparametri) ; $IVAPRE = $arrParGen['IvaPredefinito'] ; /***************************************************** * Si cerca di sistemare le lettere acentate che danno * problemi ******************************************************/ function cambia_acc($dato){ $dato = str_replace("�", "€", $dato); $dato = str_replace("�", "è", $dato); $dato = str_replace("�", "é", $dato); $dato = str_replace("�", "à", $dato); $dato = str_replace("�", "À", $dato); $dato = str_replace("�", "á", $dato); $dato = str_replace("�", "ò", $dato); $dato = str_replace("�", "ó", $dato); $dato = str_replace("�", "ì", $dato); $dato = str_replace("�", "í", $dato); $dato = str_replace("�", "ù", $dato); $dato = str_replace("�", "ú", $dato); $dato = str_replace("�", "ñ", $dato); $dato = str_replace("�", "ç", $dato); $dato = str_replace("'", "'", $dato); $dato = str_replace('"', """, $dato); $dato = str_replace('�', "°", $dato); $dato = str_replace('�', "´", $dato); $dato = str_replace('�', "»", $dato); $dato = str_replace('�', "«", $dato); $dato = str_replace('�', """, $dato); $dato = str_replace('�', """, $dato); $dato = str_replace('�', "®", $dato); $dato = str_replace("�", "™", $dato); return $dato; } /*********************************** * TogliNL * Elimina il new line dalla stringa ************************************/ function TogliNL($str) { $order = array("\r\n", "\n", "\r"); $str = str_replace($order, " ", htmlspecialchars($str)) ; return $str ; } ?>