00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00035
00036
00037 if ( ! isset ($_REQUEST['p_jrn'])) {
00038
00039 $p_jrn=GetFirstJrnIdForJrnType($_SESSION['g_dossier'],'VEN');
00040 } else
00041 {
00042 $p_jrn=$_REQUEST['p_jrn'];
00043 }
00044
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
00057
00058 if ( $sub_action == "list")
00059 {
00060
00061 if ( CheckJrn($_SESSION['g_dossier'],$_SESSION['g_user'],$p_jrn) < 1 ) {
00062 NoAccess();
00063 exit -1;
00064 }
00065
00066 echo '<div class="u_subtmenu">';
00067 echo ShowMenuJrnUser($_SESSION['g_dossier'],'VEN',0,'<td class="selectedcell">Liste</td>');
00068 echo '</div>';
00069
00070 if ( isset ( $_GET['paid']))
00071 {
00072
00073
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
00083 foreach ($_GET as $name=>$paid)
00084 {
00085 list ($id) = sscanf ($name,"rd_paid%d");
00086
00087 if ( $id == null ) continue;
00088
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
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
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
00141
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
00154 if ( $qcode != "" )
00155 {
00156
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
00182
00183
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
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
00211
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ération '.$internal.' enregistré</h2>';
00219 echo $form;
00220 echo '<hr>';
00221
00222
00223
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
00232 $doc->MoveDocumentPj($internal);
00233
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
00243
00244 if ( isset ($_POST['view_invoice']) )
00245 {
00246
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
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
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
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 }