diff --git a/html/admin/sql/patch/upgrade4.sql b/html/admin/sql/patch/upgrade4.sql index 87fb587d3..045349a22 100644 --- a/html/admin/sql/patch/upgrade4.sql +++ b/html/admin/sql/patch/upgrade4.sql @@ -44,5 +44,10 @@ update jrnx set j_centralized='f'; alter table parm_periode add p_central bool; alter table parm_periode alter p_central set default false; update parm_periode set p_central ='f'; +--for uploading doc +alter table jrn add jr_pj oid ; +alter table jrn add jr_pj_name text; +alter table jrn add jr_pj_type text; + -- always last line update version set val=5; diff --git a/html/user_jrn.php b/html/user_jrn.php index 7f7dce141..d50e79ef9 100644 --- a/html/user_jrn.php +++ b/html/user_jrn.php @@ -23,6 +23,7 @@ include_once("user_menu.php"); include_once ("constant.php"); include_once ("postgres.php"); include_once ("check_priv.php"); +include_once ("class_widget.php"); $cn=DbConnect($_SESSION['g_dossier']); include ('class_user.php'); @@ -118,7 +119,8 @@ if ( $_SESSION['g_jrn'] != -1 ) { // echo $result; echo $menu_jrn; // echo ''; - + $g_dossier=$_SESSION['g_dossier']; + $g_user=$_SESSION['g_user']; // Execute Action for g_jrn if ( $jrn_type=='VEN' ) include('user_action_ven.php'); diff --git a/include/class_widget.php b/include/class_widget.php index bb0e1755f..b222f8ad5 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -188,7 +188,7 @@ class widget { //file if (strtoupper($this->type)=="FILE") { if ( $this->readonly == false ) { - $r=''; + $r=''; } if ( $this->table==1) $r="$this->label$r"; diff --git a/include/form_input.php b/include/form_input.php index 1f0d2e079..39129cafa 100644 --- a/include/form_input.php +++ b/include/form_input.php @@ -398,12 +398,7 @@ function FormVente($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true,$p_article $r.=""; $r.="
"; - $r.=""; - $file=new widget("file"); - $file->table=1; - $r.="".$file->IOValue("pj",null,"Pièce justificative").""; - $r.="
"; - $r.="
"; + if ($view_only == false ) { $r.=''; $r.=''; @@ -660,16 +655,26 @@ for ($o = 0;$o < $p_number; $o++) { $r.='
'; $r.="Total HTVA =".round( $sum_march,2)."
"; $r.="Total = ".round($sum_with_vat,2); + + $r.="
"; if ( $p_doc == 'form' ) { - $r.='
'; + $r.=''; + // check for upload piece + $file=new widget("file"); + $file->table=1; + $r.="
"; + $r.= ""; + $r.="".$file->IOValue("pj","","Pièce justificative").""; + $r.="
"; + $r.="
"; + $r.=$data; - // $r.=''; - // If the total == 0 prevent the insert if ( $sum_with_vat != 0 ) { $r.=''; } $r.=''; + $r.='
'; } return $r; @@ -794,7 +799,11 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) // Update and set the invoice's comment $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); -if ( $Res == false ) { Rollback($p_cn); exit(" Error __FILE__ __LINE__"); }; + if ( $Res == false ) { Rollback($p_cn); exit(" Error __FILE__ __LINE__"); }; + + if ( isset ($_FILES)) + save_upload_document($p_cn,$seq); + Commit($p_cn); return $comment; @@ -816,7 +825,7 @@ if ( $Res == false ) { Rollback($p_cn); exit(" Error __FILE__ __LINE__"); }; * return: string with the form * TODO Add in parameters the infos about the company for making the invoice */ -function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p_article=1) +function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p_article=3,$saved=false) { if ( $p_array != null ) { @@ -851,7 +860,8 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p $r.=JS_SHOW_TVA; } - $r.="
"; + + $r.=""; $r.=''; $r.=''.InputType("Date ","Text","e_date",$e_date,$view_only).''; $r.=''.InputType("Echeance","Text","e_ech",$e_ech,$view_only).''; @@ -985,6 +995,18 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p } $r.="
"; + + if ( $view_only == true && $saved == false){ + // check for upload piece + $file=new widget("file"); + $file->table=1; + $r.="
"; + $r.= ""; + $r.="".$file->IOValue("pj","","Pièce justificative").""; + $r.="
"; + $r.="
"; + } + $r.=$p_submit; $r.=""; $r.="
"; @@ -1026,6 +1048,7 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p $r.=" Total =".round($total,2).""; $r.=""; }// if ( $view_only == true ) + return $r; @@ -1146,6 +1169,9 @@ function RecordAchat($p_cn,$p_array,$p_user,$p_jrn) // Update comment if comment is blank $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); } + if ( isset ($_FILES)) + save_upload_document($p_cn,$seq); + Commit($p_cn); return $comment; } @@ -1199,8 +1225,8 @@ function FormFin($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p $r.=JS_SEARCH_CARD; $r.=JS_CONCERNED_OP; } - - $r.="
"; + // $r.=''; + $r.=""; $r.=''; $r.=''.InputType("Date ","Text","e_date",$e_date,$view_only).''; @@ -1312,6 +1338,17 @@ function FormFin($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p } $r.="
"; + + if ( $view_only==true && $p_saved==false) { +// check for upload piece + $file=new widget("file"); + $file->table=1; + $r.="
"; + $r.= ""; + $r.="".$file->IOValue("pj","","Pièce justificative").""; + $r.="
"; + $r.="
"; + } $r.=$p_submit; $r.=""; $r.="
"; @@ -1418,6 +1455,9 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { // Update comment if comment is blank $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); } + if ( isset ($_FILES)) + save_upload_document($p_cn,$seq); + } Commit($p_cn); } @@ -1437,7 +1477,7 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { * - * return: string with the form */ -function FormODS($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p_article=6) +function FormODS($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p_article=6,$p_saved=false) { include_once("poste.php"); if ( $p_array != null ) { @@ -1468,7 +1508,7 @@ function FormODS($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p if ( $view_only == false) { $r.=JS_SEARCH_POSTE; } - $r.="
"; + $r.=""; $r.=''; $r.=''.InputType("Date ","Text","e_date",$e_date,$view_only).''; $r.=''.InputType("Description","Text_big","e_comment",$e_comment,$view_only).''; @@ -1558,6 +1598,18 @@ function FormODS($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p } $r.="
"; + + if ( $view_only==true && $p_saved==false) { +// check for upload piece + $file=new widget("file"); + $file->table=1; + $r.="
"; + $r.= ""; + $r.="".$file->IOValue("pj","","Pièce justificative").""; + $r.="
"; + $r.="
"; + } + $r.=$p_submit; // $r.=""; $r.="
"; @@ -1632,6 +1684,9 @@ function RecordODS($p_cn,$p_array,$p_user,$p_jrn) // Update comment if comment is blank $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); } + if ( isset ($_FILES)) + save_upload_document($p_cn,$seq); + Commit($p_cn); return $comment; } diff --git a/include/postgres.php b/include/postgres.php index 6c81956d4..c78c50e52 100644 --- a/include/postgres.php +++ b/include/postgres.php @@ -366,4 +366,32 @@ function GetArray($p_cn,$p_sql) { echo_debug(__FILE__,__LINE__,var_export($array,true)); return $array; } +/* function SavePicture + * Save a picture of a rest_id + * parameters + * - $cn database connection + * - $file array (from $_FILES) + * - $name ( name of the input) + */ +function save_upload_document ($cn,$seq) { + + $new_name=tempnam('/tmp','pj'); + if ( strlen ($_FILES['pj']['tmp_name']) != 0 ) { + if (move_uploaded_file($_FILES['pj']['tmp_name'], + $new_name)) { + // echo "Image saved"; + $oid= pg_lo_import($cn,$new_name); + ExecSql($cn,"update jrn set jr_pj=$oid, jr_pj_name='".$_FILES['pj']['name']."', ". + "jr_pj_type='".$_FILES['pj']['type']."' where jr_grpt_id=$seq"); + + } else { + echo "

Error

"; + Rollback($p_cn); + exit; + } + } + } + + + ?> diff --git a/include/user_action_ach.php b/include/user_action_ach.php index ee558c5d7..0e57965aa 100644 --- a/include/user_action_ach.php +++ b/include/user_action_ach.php @@ -119,7 +119,7 @@ if ( $action == 'new' ) { // submit button in the form $submit='

Recorded

'; - $r.=FormAch($cn,$_SESSION['g_jrn'],$_SESSION['g_user'],$submit,$HTTP_POST_VARS,true, $nb_number); + $r.=FormAch($cn,$_SESSION['g_jrn'],$_SESSION['g_user'],$submit,$HTTP_POST_VARS,true, $nb_number,true); echo '
'; echo $r; echo "
"; diff --git a/include/user_action_ods.php b/include/user_action_ods.php index e2480f365..b1bcfa189 100644 --- a/include/user_action_ods.php +++ b/include/user_action_ods.php @@ -121,7 +121,7 @@ if ( $action == 'new' ) { // submit button in the form $submit='

Recorded

'; - $r.=FormODS($cn,$_SESSION['g_jrn'],$_SESSION['g_user'],$submit,$HTTP_POST_VARS,true, $nb_number); + $r.=FormODS($cn,$_SESSION['g_jrn'],$_SESSION['g_user'],$submit,$HTTP_POST_VARS,true, $nb_number,true); echo '
'; echo $r; echo "
"; diff --git a/include/user_action_ven.php b/include/user_action_ven.php index 11ed4d74c..bb90e7977 100644 --- a/include/user_action_ven.php +++ b/include/user_action_ven.php @@ -107,13 +107,15 @@ if ( isset($_POST["record_and_print_invoice"])) { } // echo "RECORD AND PRINT INVOICE"; - $comment=RecordInvoice($cn,$HTTP_POST_VARS,$_SESSION['g_user'],$_SESSION['g_jrn']); - $nb_number=$_POST["nb_item"]; - $form=FormVenteView($cn,$g_jrn,$g_user,$HTTP_POST_VARS,$nb_number,'noform',$comment); - echo '
'; - echo $form; - echo "
"; + $comment=RecordInvoice($cn,$HTTP_POST_VARS,$_SESSION['g_user'],$_SESSION['g_jrn']); + + $nb_number=$_POST["nb_item"]; + $form=FormVenteView($cn,$g_jrn,$g_user,$HTTP_POST_VARS,$nb_number,'noform',$comment); + + echo '
'; + echo $form; + echo "
"; } diff --git a/include/user_common.php b/include/user_common.php index 8171aa2c0..7a2090b65 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -240,6 +240,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null) jrn_def_type, jr_valid, jr_tech_per, + jr_pj_name, p_closed from jrn @@ -269,6 +270,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null) jrn_def_type, jr_valid, jr_tech_per, + jr_pj_name, p_closed from jrn join jrn_def on jrn_def_id=jr_def_id @@ -328,6 +330,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null) $r.=" Description"; $r.=" Montant "; $r.="Op. Concernée"; + $r.="Document"; $r.=""; for ($i=0; $i < $Max;$i++) { @@ -388,7 +391,8 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null) $r.=""; } } - + //document + $r.="".$row['jr_pj_name'].""; // end row $r.="";