/modules/acquis/report_docacq.php
PHP | 320 lines | 263 code | 13 blank | 44 comment | 53 complexity | e569080266e7be51a1728bc6b488d80a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
- <?php
- /*$Id: report_docacq.php,v 1.24 2010/02/24 08:19:59 devincen Exp $
- --------------------------------------------------------------------------
- Gazie - Gestione Azienda
- Copyright (C) 2004-2010 - Antonio De Vincentiis Montesilvano (PE)
- (www.devincentiis.it)
- <http://gazie.sourceforge.net>
- --------------------------------------------------------------------------
- Questo programma e` free software; e` lecito redistribuirlo e/o
- modificarlo secondo i termini della Licenza Pubblica Generica GNU
- come e` pubblicata dalla Free Software Foundation; o la versione 2
- della licenza o (a propria scelta) una versione successiva.
-
- Questo programma e` distribuito nella speranza che sia utile, ma
- SENZA ALCUNA GARANZIA; senza neppure la garanzia implicita di
- NEGOZIABILITA` o di APPLICABILITA` PER UN PARTICOLARE SCOPO. Si
- veda la Licenza Pubblica Generica GNU per avere maggiori dettagli.
-
- Ognuno dovrebbe avere ricevuto una copia della Licenza Pubblica
- Generica GNU insieme a questo programma; in caso contrario, si
- scriva alla Free Software Foundation, Inc., 59
- Temple Place, Suite 330, Boston, MA 02111-1307 USA Stati Uniti.
- --------------------------------------------------------------------------
- */
- require("../../library/include/datlib.inc.php");
- require("../vendit/class/class_scadenzario.php");
- $cscad = new ClassScadenzario();
- $admin_aziend=checkAdmin();
- $message = "";
- if (isset($_GET['auxil'])) {
- $auxil = $_GET['auxil'];
- $where = " tipdoc LIKE 'AF_' ";
- } else {
- $auxil = 1;
- $where = " tipdoc LIKE 'AF_' ";
- }
- if (isset($_GET['protoc'])) {
- if ($_GET['protoc'] > 0) {
- $protocollo = $_GET['protoc'];
- $auxil = $_GET['auxil']."&protoc=".$protocollo;
- $where = " tipdoc LIKE 'AF_' AND protoc = $protocollo ";
- $passo = 1;
- }
- } else {
- $protocollo ='';
- }
-
- if ((isset($_GET['clientdoc'])) and (!empty($_GET['clientdoc']))) {
- $clientdoc = $_GET['clientdoc'];
- $auxil = $_GET['auxil'];
- $where = " tipdoc LIKE 'AF_' AND ragso1 like '%".addslashes($clientdoc)."%'";
- $passo = 10000;
- $clientdoc = stripslashes($clientdoc);
- }
-
- if ((isset($_GET['per_data'])) and (!empty($_GET['per_data']))) {
- $per_data_selected = "checked";
- /*
- * gioemi=7&mesemi=2&annemi=2001
- */
- $auxil = $_GET['auxil'];
- $data_search_da = $_GET['annemi']."-".$_GET['mesemi']."-".$_GET['gioemi'];
- $data_search_a = $_GET['annami']."-".$_GET['mesami']."-".$_GET['gioami'];
- if (!empty($where)) {
- $where .= " AND datemi >= '".$data_search_da."' AND datemi <= '".$data_search_a."' ";
- } else {
- $where = " tipdoc LIKE 'AF_' datemi >= '".$data_search_da."' and datemi <= '".$data_search_a."' ";
- }
-
- $where .= " GROUP BY protoc, datfat ";
-
- } else {
- $_GET['annemi'] = date("Y");
- $_GET['mesemi'] = date("m");
- $_GET['gioemi'] = date("d");
- $_GET['annami'] = date("Y");
- $_GET['mesami'] = date("m");
- $_GET['gioami'] = date("d");
- }
-
-
-
- if (isset($_GET['all'])) {
- $where = "tipdoc LIKE 'AF_' GROUP BY protoc, datfat";
- $auxil = $_GET['auxil']."&all=yes";
- $passo = 100000;
- $protocollo ='';
- }
-
- $titolo="Documenti d'acquisto";
- require("../../library/include/header.php");
- $script_transl=HeadMain();
- ?>
- <table border="0" cellpadding="3" cellspacing="1" align="center" width="70%">
- <tr>
- <td class="FacetFormHeaderFont"><a href="admin_docacq.php?Insert&tipdoc=AFA" accesskey="F">Registra Fattura d'Acquisto Merce</a></td>
- <td class="FacetFormHeaderFont"><a href="admin_docacq.php?Insert&tipdoc=AFC" accesskey="N">Registra Nota Credito per Merce</a></td>
- <td class="FacetFormHeaderFont"><a href="accounting_documents.php?type=A" accesskey="C">Contabilizzazione fatture</a></td>
- </tr>
- </table>
- <form method="GET" >
- <div align="center" class="FacetFormHeaderFont"><?php echo $titolo; ?>
- </div>
- <?php
- if (!isset($_GET['field']) || ($_GET['field'] == 2) || (empty($_GET['field'])))
- $orderby = "datfat DESC, protoc DESC";
- $recordnav = new recordnav($gTables['tesdoc'], $where, $limit, $passo);
- $recordnav -> output();
- ?>
- <table class="Tlarge">
- <tr>
- <td colspan="2" class="FacetFieldCaptionTD">Protocollo:
- <input type="text" name="protoc" value="<?php if (isset($protocollo)) print $protocollo; ?>" maxlength="6" size="3" tabindex="1" class="FacetInput">
- </td>
- <td colspan="1" class="FacetFieldCaptionTD">Cliente:
- <input type="text" name="clientdoc" value="<?php if (isset($clientdoc)) print $clientdoc; ?>" maxlength="100" size="16" tabindex="1" class="FacetInput">
- </td>
- <td colspan="2" class="FacetFieldCaptionTD">
- <input type="checkbox" value="per_data" name="per_data" <?=$per_data_selected?>> Da:
- <?
- // select del giorno
- echo "\t <select name=\"gioemi\" class=\"FacetSelect\" >\n";
- for( $counter = 1; $counter <= 31; $counter++ )
- {
- $selected = "";
- if($counter == $_GET['gioemi'])
- $selected = "selected";
- echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
- }
- echo "\t </select>\n";
- // select del mese
- echo "\t <select name=\"mesemi\" class=\"FacetSelect\" >\n";
- for( $counter = 1; $counter <= 12; $counter++ )
- {
- $selected = "";
- if($counter == $_GET['mesemi'])
- $selected = "selected";
- $nome_mese = ucwords(strftime("%B", mktime (0,0,0,$counter,1,0)));
- echo "\t\t <option value=\"$counter\" $selected >$nome_mese</option>\n";
- }
- echo "\t </select>\n";
- // select del anno
- echo "\t <select name=\"annemi\" class=\"FacetSelect\" onchange=\"this.form.submit()\">\n";
- for( $counter = date("Y")-10; $counter <= date("Y")+10; $counter++ )
- {
- $selected = "";
- if($counter == $_GET['annemi'])
- $selected = "selected";
- echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
- }
- echo "\t </select>\n";
- ?>
- A:
- <?
- // select del giorno
- echo "\t <select name=\"gioami\" class=\"FacetSelect\" >\n";
- for( $counter = 1; $counter <= 31; $counter++ )
- {
- $selected = "";
- if($counter == $_GET['gioami'])
- $selected = "selected";
- echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
- }
- echo "\t </select>\n";
- // select del mese
- echo "\t <select name=\"mesami\" class=\"FacetSelect\" >\n";
- for( $counter = 1; $counter <= 12; $counter++ )
- {
- $selected = "";
- if($counter == $_GET['mesami'])
- $selected = "selected";
- $nome_mese = ucwords(strftime("%B", mktime (0,0,0,$counter,1,0)));
- echo "\t\t <option value=\"$counter\" $selected >$nome_mese</option>\n";
- }
- echo "\t </select>\n";
- // select del anno
- echo "\t <select name=\"annami\" class=\"FacetSelect\" onchange=\"this.form.submit()\">\n";
- for( $counter = date("Y")-10; $counter <= date("Y")+10; $counter++ )
- {
- $selected = "";
- if($counter == $_GET['annami'])
- $selected = "selected";
- echo "\t\t <option value=\"$counter\" $selected >$counter</option>\n";
- }
- echo "\t </select>\n";
- ?>
- </td>
-
- <td>
- <input type="submit" name="search" value="Cerca" tabindex="1" onClick="javascript:document.report.all.value=1;">
- </td>
- <td>
- <input type="submit" name="all" value="Mostra tutti" onClick="javascript:document.report.all.value=1;">
- </td>
- </tr>
- <tr>
- <?php
- // creo l'array (header => campi) per l'ordinamento dei record
- $headers_tesdoc = array (
- "Prot." => "protoc",
- "Tipo" => "tipdoc",
- "Numero" => "numfat",
- "Data" => "datfat",
- "Cliente" => "ragso1",
- "Totale" => "",
- "Status" => "",
- "Stampa" => "",
- "Cancella" => ""
- );
- $linkHeaders = new linkHeaders($headers_tesdoc);
- $linkHeaders -> output();
- ?>
- </tr>
- <?php
- $rs_last_doc = gaz_dbi_dyn_query("MAX(protoc) AS maxpro, YEAR(datfat) AS y", $gTables['tesdoc'],"tipdoc LIKE 'AF_' GROUP BY y " ,'protoc DESC');
- while ($last_doc = gaz_dbi_fetch_array($rs_last_doc)){
- $lt_doc[$last_doc['y']]=$last_doc['maxpro'];
- }
-
- //recupero le testate in base alle scelte impostate
- $result = gaz_dbi_dyn_query($gTables['tesdoc'].".*,".$gTables['anagra'].".ragso1", $gTables['tesdoc']." LEFT JOIN ".$gTables['clfoco']." ON ".$gTables['tesdoc'].".clfoco = ".$gTables['clfoco'].".codice LEFT JOIN ".$gTables['anagra'].' ON '.$gTables['clfoco'].'.id_anagra = '.$gTables['anagra'].'.id', $where, $orderby,$limit, $passo);
- $ctrlprotoc = "";
- while ($a_row = gaz_dbi_fetch_array($result)) {
- $y=substr($a_row['datfat'],0,4);
- if ($a_row["tipdoc"] == 'AFA') {
- $tipodoc="Fattura";
- $modulo="stampa_docacq.php?id_tes=".$a_row['id_tes'];
- $modifi="admin_docacq.php?Update&id_tes=".$a_row['id_tes'];
- } elseif ($a_row["tipdoc"] == 'AFC') {
- $tipodoc="Nota Credito";
- $modulo="stampa_docacq.php?id_tes=".$a_row['id_tes'];
- $modifi="admin_docacq.php?Update&id_tes=".$a_row['id_tes'];
- }
-
- if ($a_row["protoc"] <> $ctrlprotoc) {
- print "<tr>";
- if (! empty ($modifi)) {
- print "<td class=\"FacetDataTD\"><a href=\"".$modifi."\">".$a_row["protoc"]."</td>";
- } else {
- print "<td class=\"FacetDataTD\">".$a_row["protoc"]." </td>";
- }
- print "<td class=\"FacetDataTD\">".$tipodoc." </td>";
- print "<td class=\"FacetDataTD\">".$a_row["numfat"]." </td>";
- print "<td class=\"FacetDataTD\">".$a_row["datfat"]." </td>";
- print "<td class=\"FacetDataTD\">".$a_row["ragso1"]." </td>";
-
- try {
- $totivafat = 0;
- $ivacast = 0;
- //scarico tutte le variabili precedentemente valorizzate
- //mi ricavo il totale dell'ultima fattura
- $ay_rigdoc = $cscad->get_all_rigdoc($a_row['id_tes'], $gTables['rigdoc']);
- //recupero i dati relativi alla fattura
- $ay_tesdoc = $cscad->get_tesdoc_from_idtes($a_row['id_tes'], $gTables['tesdoc'], $gTables['pagame']);
- //calcolo il castelletto IVA
- $ay_castle = $cscad->get_castle_for_rigdoc($ay_rigdoc, $ay_tesdoc['tesdoc']['sconto']);
- //calcolo tutte le spese relative alla fattura appena ricevuta
- $tot_spese = $cscad->calc_tot_spese($ay_tesdoc);
- //inserisco nella variabile last l'ultimo entry dell'array decalc_castle
- $last = count($ay_castle['decalc_castle']);
- //inserisco nella variabile acc_val il valore di tot_spese
- $acc_val = $tot_spese;
- // leggo l'intero array castle e lo analizzo
- foreach ($ay_castle['castle'] as $k=>$v) {
- //recupero l'iva che interessa il rigo del castelletto e la salvo in variabile
- $vat = $cscad->get_iva($k, $gTables['aliiva']);
- if (isset($ay_castle['decalc_castle'][$k])) {
- $last--;
- if ($last==0) {
- $v += $acc_val;
- $ay_castle['totimpfat'] += $acc_val;
- } else {
- $decalc=round($tot_spese*$v/$ay_castle['totimp_decalc'],2);
- $v += $decalc;
- $ay_castle['totimpfat'] += $decalc;
- $acc_val-=$decalc;
- }
- }
- $ivacast = round($v*$vat['aliquo'])/100;
- $totivafat += $ivacast;
- }
- // calcolo il totale importo della fattura
- $tot_fattura = $ay_castle['totimpfat']+$totivafat+$ay_tesdoc['stamp']-$ay_castle['rit'];
- $tot_finale = $tot_finale+$tot_fattura;
- } catch (Exception $e) {
- $feedback = $e->getMessage();
- }
- if (isset($feedback)) {
- echo "<td class=\"FacetDataTD\"> ".$feedback." </td>";
- } else {
- echo "<td class=\"FacetDataTD\"> € ".$tot_fattura." </td>";
- }
-
- if ($a_row["id_con"] > 0) {
- echo "<td class=\"FacetDataTD\" align=\"center\"><a href=\"../contab/admin_movcon.php?id_tes=".$a_row["id_con"]."&Update\">Cont. n.".$a_row["id_con"]."</a></td>";
- } else {
- echo "<td class=\"FacetDataTD\" align=\"center\"><a href=\"accounting_documents.php?type=A&last=".$a_row["protoc"]."\">Contabilizza</a></td>";
- }
- print "<td class=\"FacetDataTD\"><a href=\"".$modulo."\"><center><img src=\"../../library/images/stampa.gif\" alt=\"Stampa\" border=\"0\"></a></td>";
- if (($lt_doc[$y]==$a_row['protoc']) && ($a_row["id_con"]==0)) {
- print "<td class=\"FacetDataTD\"><a href=\"delete_docacq.php?id_tes=".$a_row["id_tes"]."\"><center><img src=\"../../library/images/x.gif\" alt=\"Cancella\" border=\"0\"></a></td>";
- } else {
- print "<td class=\"FacetDataTD\"></td>";
- }
- print "</tr>\n";
- }
- $ctrlprotoc = $a_row["protoc"];
- }
- ?>
- </form>
- </table>
- <!-- CREAZIONE TABELLA CONTENTE IL TOTALE GENERICO DEL REPORT RICHIESTO -->
- <table align="right" border="1" cellspacing="1">
- <tr>
- <td class="FacetFieldCaptionTD"><strong>TOTALE</strong></td>
- <td class="FacetDataTD">€ <?=$tot_finale?></td>
- </tr>
- </table>
- </body>
- </html>