Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

facture.inc.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 1.10 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 require_once('class_jrn.php');
00022 require_once('user_form_ven.php');
00023 require_once('jrn.php');
00024 require_once("class_document.php");
00025 require_once("class_fiche.php");
00026 require_once("check_priv.php");
00034 // First we show the menu
00035 // If nothing is asked the propose a blank form
00036 // to enter a new invoice
00037 if ( ! isset ($_REQUEST['p_jrn'])) {
00038   // no journal are selected so we select the first one
00039   $p_jrn=GetFirstJrnIdForJrnType($_SESSION['g_dossier'],'VEN'); 
00040 } else
00041 {
00042   $p_jrn=$_REQUEST['p_jrn'];
00043 }
00044 // for the back button
00045 $retour="";
00046 $h_url="";
00047 
00048 if ( isset ($_REQUEST['url'])) 
00049 {
00050   $retour=sprintf('<A class="mtitle" HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
00051   $h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
00052 }
00053 
00054 $sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
00055 //-----------------------------------------------------
00056 // If a list of invoice is asked
00057 // 
00058 if ( $sub_action == "list") 
00059 {
00060    // Check privilege
00061    if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) < 1 )    {
00062         NoAccess();
00063         exit -1;
00064    }
00065   // show the menu with the list item selected
00066   echo '<div class="u_subtmenu">';
00067   echo ShowMenuJrnUser($_SESSION['g_dossier'],'VEN',0,'<td class="selectedcell">Liste</td>');
00068   echo '</div>';
00069   // Ask to update payment
00070   if ( isset ( $_GET['paid'])) 
00071     {
00072       // reset all the paid flag because the checkbox is post only
00073       // when checked
00074       foreach ($_GET as $name=>$paid) 
00075         {
00076             list($ad) = sscanf($name,"set_jr_id%d");
00077             if ( $ad == null ) continue;
00078             $sql="update jrn set jr_rapt='' where jr_id=$ad";
00079             $Res=ExecSql($cn,$sql);
00080             
00081         }
00082         // set a paid flag for the checked box
00083       foreach ($_GET as $name=>$paid) 
00084         {
00085           list ($id) = sscanf ($name,"rd_paid%d");
00086           
00087           if ( $id == null ) continue;
00088           //      echo "Mise à jour $id";
00089           $paid=($paid=='on')?'paid':'';
00090           $sql="update jrn set jr_rapt='$paid' where jr_id=$id";
00091           $Res=ExecSql($cn,$sql);
00092         }
00093       
00094       }
00095   echo $retour;
00096   echo '<div class="u_redcontent">';
00097 
00098   
00099 
00100   echo '<form method= "GET" action="commercial.php">';
00101 
00102   $hid=new widget("hidden");
00103   
00104   $hid->name="p_action";
00105   $hid->value="facture";
00106   echo $hid->IOValue();
00107 
00108 
00109   $hid->name="sa";
00110   $hid->value="list";
00111   echo $hid->IOValue();
00112 
00113 
00114 
00115   $w=new widget("select");
00116   //  Add filter on the year
00117   $filter_year=" where p_exercice='".$User->getExercice()."'";
00118 
00119   $periode_start=make_array($cn,"select p_id,to_char(p_start,'DD-MM-YYYY') ".
00120                             " from parm_periode $filter_year order by p_id",1);
00121   // User is already set User=new cl_user($cn);
00122   $current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->GetPeriode();
00123   $w->selected=$current;
00124 
00125   echo 'Période  '.$w->IOValue("p_periode",$periode_start);
00126   $qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
00127   
00128   echo JS_SEARCH_CARD;
00129   $w=new widget('js_search_only');
00130   $w->name='qcode';
00131   $w->value=$qcode;
00132   $w->label='';
00133   $w->extra='9';
00134   $w->table=0;
00135   $sp= new widget("span");
00136 
00137   echo $sp->IOValue("qcode_label","",$qcode);
00138   echo $w->IOValue();
00139 echo $w->Submit('gl_submit','Rechercher');
00140   // Show list of sell
00141   // Date - date of payment - Customer - amount
00142  if ( $current == -1) {
00143    $cond=" and jr_tech_per in (select p_id from parm_periode where p_exercice='".$User->getExercice()."')";
00144  } else {
00145    $cond=" and jr_tech_per=".$current;
00146  }
00147   $sql=SQL_LIST_ALL_INVOICE.$cond." and jr_def_type='VEN'" ;
00148   $step=$_SESSION['g_pagesize'];
00149   $page=(isset($_GET['offset']))?$_GET['page']:1;
00150   $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00151 
00152   $l="";
00153   // check if qcode contains something
00154   if ( $qcode != "" )
00155     {
00156       // add a condition to filter on the quick code
00157       $l=" and jr_grpt_id in (select j_grpt from jrnx where j_qcode='$qcode') ";
00158     }
00159 
00160   list($max_line,$list)=ListJrn($cn,0,"where jrn_def_type='VEN' $cond $l "
00161                                 ,null,$offset,1);
00162   $bar=jrn_navigation_bar($offset,$max_line,$step,$page);
00163 
00164   echo "<hr> $bar";
00165   echo $list;
00166   echo "$bar <hr>";
00167   if ( $max_line !=0 )
00168     echo $hid->Submit('paid','Mise à jour paiement');
00169   echo '</FORM>';
00170   echo $retour;
00171 
00172   echo '</div>';
00173 
00174  exit();
00175 } 
00176 //-----------------------------------------------------
00177 echo '<div class="u_subtmenu">';
00178 echo ShowMenuJrnUser($_SESSION['g_dossier'],'VEN',$p_jrn,'<td class="cell"><A class="mtitle" HREF="commercial.php?liste&p_action=facture&sa=list">Liste</A></td>');
00179 echo '</div>';
00180 //-----------------------------------------------------
00181 // if we request to add an item 
00182 // the $_POST['add_item'] is set
00183 // or if we ask to correct the invoice
00184 if ( isset ($_POST['add_item']) || isset ($_POST["correct_new_invoice"])  ) 
00185 {
00186  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00187         NoAccess();
00188         exit -1;
00189    }
00190 
00191   $nb_item=$_POST['nb_item'];
00192   if ( isset ($_POST['add_item']))
00193     $nb_item++;
00194   $form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),$_POST,false,$nb_item);
00195   echo '<div class="u_redcontent">';
00196   echo $form;
00197   echo '</div>';
00198   exit();
00199 }
00200 //-----------------------------------------------------
00201 // we want to save the invoice and to generate a invoice
00202 //
00203 if ( isset($_POST['record_and_print_invoice'])) 
00204 {
00205  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00206         NoAccess();
00207         exit -1;
00208    }
00209 
00210   // First we save the invoice, the internal code will be used to change the description
00211   // and upload the file
00212   list ($internal,$e)=RecordInvoice($cn,$_POST,$User,$p_jrn);
00213 
00214   
00215   $form=FormVenteView($cn,$p_jrn,$User->GetPeriode(),$_POST,$_POST['nb_item'],'noform','');
00216 
00217   echo '<div class="u_redcontent">';
00218   echo '<h2 class="info"> Op&eacute;ration '.$internal.' enregistr&eacute;</h2>';
00219   echo $form;
00220   echo '<hr>';
00221   
00222   // Show the details of the encoded invoice 
00223   // and the url of the invoice
00224   if ( isset($_POST['gen_invoice'])) 
00225     {
00226           $doc=new Document($cn);
00227           $doc->f_id=$_POST['e_client'];
00228           $doc->md_id=$_POST['gen_doc'];
00229           $doc->ag_id=0;
00230           $str_file=$doc->Generate();
00231           // Move the document to the jrn
00232           $doc->MoveDocumentPj($internal);
00233           // Update the comment with invoice number
00234           $sql="update jrn set jr_comment='Facture ".$doc->d_number."' where jr_internal='$internal'";
00235           ExecSql($cn,$sql);
00236           echo $str_file;
00237     }
00238   echo '</form>';
00239   exit();
00240 }
00241 //-----------------------------------------------------
00242 // we show the confirmation screen it is proposed here to generate the
00243 // invoice
00244 if ( isset ($_POST['view_invoice']) ) 
00245 {
00246    // Check privilege
00247    if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) < 1 )    {
00248         NoAccess();
00249         exit -1;
00250    }
00251   $nb_number=$_POST["nb_item"];
00252   if ( form_verify_input($cn,$p_jrn,$User->GetPeriode(),$HTTP_POST_VARS,$nb_number) == true)
00253     {
00254       $form=FormVenteView($cn,$p_jrn,$User->GetPeriode(),$HTTP_POST_VARS,$nb_number);
00255 
00256     } else {
00257       // Check failed : invalid date or quantity
00258       echo_error("Cannot validate ");
00259       $form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),$HTTP_POST_VARS,false,$nb_number);
00260     }
00261 
00262   echo '<div class="u_redcontent">';
00263   echo         $form;
00264   echo '</div>';
00265   exit();
00266 
00267 }
00268 
00269 
00270 
00271 //-----------------------------------------------------
00272 // By default we add a new invoice
00273 if ( $p_jrn != -1 ) 
00274 {
00275  if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) != 2 )    {
00276         exit -1;
00277    }
00278 
00279   $jrn=new jrn($cn,  $p_jrn);
00280   echo_debug('facture.inc.php.php',__LINE__,"Blank form");
00281   // Show an empty form of invoice
00282   $form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),null,false,$jrn->GetDefLine());
00283   echo '<div class="u_redcontent">';
00284   echo $form;
00285   echo '</div>';
00286 }