diff --git a/html/commercial.php b/html/commercial.php index 9b465acbb..eb7c80c72 100644 --- a/html/commercial.php +++ b/html/commercial.php @@ -76,6 +76,7 @@ echo ShowItem(array( array('?p_action=client','Client'), array('?p_action=facture','Facture'), array('?p_action=fournisseur','Fournisseur'), + array('?p_action=depense','Dépense'), array('?p_action=contact','Contact'), array('?p_action=suivi_courrier','Suivi courrier'), array('?p_action=pref','Préférence'), @@ -109,7 +110,7 @@ if ( $p_action == "client" ) // Fournisseur if ( $p_action == 'fournisseur') { - require_once("fournisseur.inc.php"); + require_once("supplier.inc.php"); } //////////////////////////////////////////////////////////////////////////////// // action @@ -130,3 +131,9 @@ if ( $p_action == 'contact') { require_once("contact.inc.php"); } +//////////////////////////////////////////////////////////////////////////////// +// Expense +if ( $p_action == 'depense') +{ + require_once("depense.inc.php"); +} diff --git a/include/class_document.php b/include/class_document.php index b2239631f..648ff20b6 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -593,7 +593,7 @@ class Document $sql='delete from document where d_id='.$this->d_id; ExecSql($this->db,$sql); } - /*!\brief Copy a document from the table document into the concerned row + /*!\brief Move a document from the table document into the concerned row * the document is not copied : it is only a link * * \param $p_internal internal code diff --git a/include/class_supplier.php b/include/class_supplier.php new file mode 100644 index 000000000..8eb819637 --- /dev/null +++ b/include/class_supplier.php @@ -0,0 +1,158 @@ +fiche_def_ref=FICHE_TYPE_FOURNISSEUR; + fiche::fiche($p_cn,$p_id) ; + + } + /*! \brief Get all info contains in the view + * thanks to the poste elt (account) + */ + function GetFromPoste($p_poste=0) { + $this->poste=($p_poste==0)?$this->poste:$p_poste; + $sql="select * from vw_supplier where poste_comptable=".$this->poste; + $Res=ExecSql($this->cn,$sql); + if ( pg_NumRows($Res) == 0) return null; + // There is only _one_ row by supplier + $row=pg_fetch_array($Res,0); + $this->name=$row['name']; + $this->id=$row['f_id']; + $this->street=$row['rue']; + $this->cp=$row['code_postal']; + $this->country=$row['pays']; + $this->vat_number=$row['tva_num']; + + } + +/*! \function Summary + ************************************************** + \Brief show the default screen + * + * parm : + * - p_search (filter) + * gen : + * - + * return: string to display + */ + function Summary($p_search) + { + $p_search=FormatString($p_search); + $url=urlencode($_SERVER['REQUEST_URI']); + $script=$_SERVER['SCRIPT_NAME']; + // Creation of the nav bar + // Get the max numberRow + $all_supplier=$this->CountByDef($this->fiche_def_ref,$p_search); + // Get offset and page variable + $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0; + $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1; + $bar=jrn_navigation_bar($offset,$all_supplier,$_SESSION['g_pagesize'],$page); + // set a filter ? + $search=""; + if ( trim($p_search) != "" ) + { + $search=" and f_id in +(select f_id from jnt_fic_att_value + join fiche using (f_id) + join attr_value using (jft_id) + where + ad_id=1 and av_text ~* '$p_search')"; + } + // Get The result Array + $step_supplier=$this->GetAll($offset,$search); + if ( $all_supplier == 0 ) return ""; + $r=$bar; + $r.=' + + + + + + +'; + if ( sizeof ($step_supplier ) == 0 ) + return $r; + foreach ($step_supplier as $supplier ) { + $r.=""; + $e=sprintf(' ', + $script,$supplier->id,$url); + + $r.=""; + $r.=""; + $r.=""; + + $post=new poste($this->cn,$supplier->strAttribut(ATTR_DEF_ACCOUNT)); + $a=$post->GetSoldeDetail(); + $r.=sprintf('',$a['solde']); + $r.="'; + + $r.=""; + + } + $r.="
Quick CodeNomAdresseSoldeAction
$e".$supplier->strAttribut(ATTR_DEF_QUICKCODE)."".$supplier->strAttribut(ATTR_DEF_NAME)."".$supplier->strAttribut(ATTR_DEF_ADRESS). + " ".$supplier->strAttribut(ATTR_DEF_CP). + " ".$supplier->strAttribut(ATTR_DEF_PAYS). + " %15.2f€"; + + $r.=sprintf('C - ', + $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE),$url); + $r.=sprintf('A - ', + $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE) ,$url); + + + + $r.='F -'; + + $r.='
"; + $r.=$bar; + return $r; + } + +} + +?> diff --git a/include/contact.inc.php b/include/contact.inc.php index 965c7cb34..78d5ca669 100644 --- a/include/contact.inc.php +++ b/include/contact.inc.php @@ -77,6 +77,7 @@ if ( isset ($_POST['mod'])) $contact=new contact($cn,$f_id); $contact->Save(); + $sub_action="list"; } // by default open liste if ( $sub_action == "" ) diff --git a/include/depense.inc.php b/include/depense.inc.php new file mode 100644 index 000000000..283695e5e --- /dev/null +++ b/include/depense.inc.php @@ -0,0 +1,236 @@ +',urldecode($_REQUEST['url'])); + $h_url=sprintf('',urldecode($_REQUEST['url'])); +} + +$sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:""; +//////////////////////////////////////////////////////////////////////////////// +// If a list of depense is asked +// +if ( $sub_action == "list") +{ + + // show the menu with the list item selected + echo '
'; + echo ShowMenuJrnUser($_SESSION['g_dossier'],'ACH',0,'Liste'); + echo '
'; + // Ask to update payment + if ( isset ( $_GET['paid'])) + { + // reset all the paid flag because the checkbox is post only + // when checked + foreach ($_GET as $name=>$paid) + { + list($ad) = sscanf($name,"set_jr_id%d"); + if ( $ad == null ) continue; + $sql="update jrn set jr_rapt='' where jr_id=$ad"; + $Res=ExecSql($cn,$sql); + + } + // set a paid flag for the checked box + foreach ($_GET as $name=>$paid) + { + list ($id) = sscanf ($name,"rd_paid%d"); + + if ( $id == null ) continue; + // echo "Mise à jour $id"; + $paid=($paid=='on')?'paid':''; + $sql="update jrn set jr_rapt='$paid' where jr_id=$id"; + $Res=ExecSql($cn,$sql); + } + + } + + echo '
'; + + + + echo '
'; + + $hid=new widget("hidden"); + + $hid->name="p_action"; + $hid->value="depense"; + echo $hid->IOValue(); + + + $hid->name="sa"; + $hid->value="list"; + echo $hid->IOValue(); + + + + $w=new widget("select"); + + $periode_start=make_array($cn,"select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode order by p_id"); + // User is already set User=new cl_user($cn); + $current=(isset($_GET['p_periode']))?$_GET['p_periode']:$User->GetPeriode(); + $w->selected=$current; + + echo 'Période '.$w->IOValue("p_periode",$periode_start).$w->Submit('gl_submit','Valider'); + $qcode=(isset($_GET['qcode']))?$_GET['qcode']:""; + printf ('Tiers QuickCode: ', + $qcode); + echo $retour; + // Show list of sell + // Date - date of payment - Customer - amount + $sql=SQL_LIST_ALL_INVOICE." and jr_tech_per=".$current." and jr_def_type='ACH'" ; + $step=$_SESSION['g_pagesize']; + $page=(isset($_GET['offset']))?$_GET['page']:1; + $offset=(isset($_GET['offset']))?$_GET['offset']:0; + + $l=""; + // check if qcode contains something + if ( $qcode != "" ) + { + // add a condition to filter on the quick code + $l=" and jr_grpt_id in (select j_grpt from jrnx where j_qcode='$qcode') "; + } + + list($max_line,$list)=ListJrn($cn,0,"where jrn_def_type='ACH' and jr_tech_per=$current $l " + ,null,$offset,1); + $bar=jrn_navigation_bar($offset,$max_line,$step,$page); + + echo "
$bar"; + echo $list; + echo "$bar
"; + if ( $max_line !=0 ) + echo $hid->Submit('paid','Mise à jour paiement'); + echo '
'; + echo $retour; + + echo '
'; + + exit(); +} +//////////////////////////////////////////////////////////////////////////////// +echo '
'; +echo ShowMenuJrnUser($_SESSION['g_dossier'],'ACH',$p_jrn,'Liste'); +echo '
'; +//////////////////////////////////////////////////////////////////////////////// +// if we request to add an item +// the $_POST['add_item'] is set +// or if we ask to correct the invoice +if ( isset ($_POST['add_item']) || isset ($_POST["correct_new_invoice"]) ) +{ + $nb_item=$_POST['nb_item']; + $nb_item++; + // Submit button in the form + $submit=' + '; + + $form=FormAchInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,$submit,false,$nb_item); + echo '
'; + echo $form; + echo '
'; + exit(); +} +//////////////////////////////////////////////////////////////////////////////// +// we want to save the invoice and to generate a invoice +// +if ( isset($_POST['save'])) +{ + // we save the expense + list ($internal,$c)=RecordSell($cn,$_POST,$User,$p_jrn); + + + $form=FormAchView($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,"",$_POST['nb_item'],false); + + echo '
'; + echo '

Opération '.$internal.' enregistré

'; + echo $form; + echo '
'; + echo ''; + echo ' + '; + exit(); +} +//////////////////////////////////////////////////////////////////////////////// +// we show the confirmation screen +// +if ( isset ($_POST['view_invoice']) ) +{ + $nb_number=$_POST["nb_item"]; + $submit=''; + $submit.=''; + if ( form_verify_input ($cn,$p_jrn,$User->GetPeriode(),$_POST,$nb_number) == true ) { + // Should use a read only view instead of FormAch + // where we can check + $form=FormAchView($cn,$p_jrn,$User->GetPeriode(),$_POST,$submit,$nb_number); + } else { + // if something goes wrong, correct it + $submit=' + '; + $form=FormAchInput($cn,$p_jrn,$User->GetPeriode(),$_POST,$submit, false, $nb_number); + } + + echo '
'; + echo $form; + echo '
'; + exit(); + +} + + + +//////////////////////////////////////////////////////////////////////////////// +// By default we add a new invoice +if ( $p_jrn != -1 ) +{ + $jrn=new jrn($cn, $p_jrn); + echo_debug('depense.inc.php',__LINE__,"Blank form"); + // Submit button in the form + $submit=' + '; + // Show an empty form of invoice + $form=FormAchInput($cn,$p_jrn,$User->GetPeriode(),null,$submit,false,$jrn->getDefLine('cred')); + echo '
'; + echo $form; + echo '
'; +} diff --git a/include/facture.inc.php b/include/facture.inc.php index f20c13596..b6773d820 100644 --- a/include/facture.inc.php +++ b/include/facture.inc.php @@ -26,13 +26,6 @@ require_once("class_fiche.php"); /*!\brief the purpose off this file is to create invoices, to record them and to generate * them, and of course to save them into the database * - * \note we update also the jrn. - * jr_pj oid - * jr_pj_name text - * jr_pj_type text - * \todo link the table document and jrn, remove those field to make it cleaner and to permit to - * several operation for one document. For that we should have a new item in the menu (link - * document and operation) To be analyzed */ var_dump($_REQUEST); @@ -40,24 +33,22 @@ var_dump($_REQUEST); // If nothing is asked the propose a blank form // to enter a new invoice if ( ! isset ($_REQUEST['p_jrn'])) { - // no journal are selected so we select the first one - // $p_jrn=GetFirstJrnIdForJrnType($_SESSION['g_dossier'],'VEN'); - $p_jrn=-1; + // no journal are selected so we select the first one + $p_jrn=GetFirstJrnIdForJrnType($_SESSION['g_dossier'],'VEN'); + // $p_jrn=-1; } else { $p_jrn=$_REQUEST['p_jrn']; } // for the back button +$retour=""; +$h_url=""; + if ( isset ($_REQUEST['url'])) { $retour=sprintf('',urldecode($_REQUEST['url'])); $h_url=sprintf('',urldecode($_REQUEST['url'])); } -else -{ - $retour=""; - $h_url=""; -} $sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:""; //////////////////////////////////////////////////////////////////////////////// @@ -68,7 +59,7 @@ if ( $sub_action == "list") // show the menu with the list item selected echo '
'; - echo ShowMenuJrnUser($_SESSION['g_dossier'],'VEN',$p_jrn,'Liste'); + echo ShowMenuJrnUser($_SESSION['g_dossier'],'VEN',0,'Liste'); echo '
'; // Ask to update payment if ( isset ( $_GET['paid'])) @@ -127,7 +118,7 @@ if ( $sub_action == "list") $qcode=(isset($_GET['qcode']))?$_GET['qcode']:""; printf ('Tiers QuickCode: ', $qcode); - echo $retour; + // Show list of sell // Date - date of payment - Customer - amount $sql=SQL_LIST_ALL_INVOICE." and jr_tech_per=".$current." and jr_def_type='VEN'" ; @@ -153,6 +144,7 @@ if ( $sub_action == "list") if ( $max_line !=0 ) echo $hid->Submit('paid','Mise à jour paiement'); echo ''; + echo $retour; echo '
'; @@ -238,9 +230,9 @@ if ( isset ($_POST['view_invoice']) ) if ( $p_jrn != -1 ) { $jrn=new jrn($cn, $p_jrn); - echo_debug('user_action_ven.php',__LINE__,"Blank form"); + echo_debug('facture.inc.php.php',__LINE__,"Blank form"); // Show an empty form of invoice - $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),null,false,$jrn->GetDefLine('cred')); + $form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),null,false,$jrn->GetDefLine('cred')); echo '
'; echo $form; echo '
'; diff --git a/include/supplier.inc.php b/include/supplier.inc.php new file mode 100644 index 000000000..6fe46d9cc --- /dev/null +++ b/include/supplier.inc.php @@ -0,0 +1,173 @@ + + +remove(); + $sub_action="list"; +} +//////////////////////////////////////////////////////////////////////////////// +// Add card +if ( $sub_action=="insert" ) +{ + $retour=sprintf('', + urldecode($_REQUEST['url'])); + + $supplier=new Supplier($cn); + $supplier->Save($_REQUEST['fd_id']); + echo $retour; + echo ""; + echo $supplier->Display(true); + echo "
"; + echo $retour; + +} +//////////////////////////////////////////////////////////////////////////////// +// Save modification +if ( isset ($_POST['mod'])) +{ + // modification is asked + $f_id=$_REQUEST['f_id']; + + $sup=new Supplier($cn,$f_id); + $sup->Save(); +} +// by default open liste +if ( $sub_action == "" ) + $sub_action="list"; +//////////////////////////////////////////////////////////////////////////////// +//Display a blank card +if ( $sub_action=="blank") +{ + $retour=sprintf('', + "commercial.php?p_action=fournisseur"); + echo '
'; + + echo $retour; + $c=new Supplier($cn); + echo '
'; + echo ''; + echo ''; + echo ''; + echo $c->blank($_GET['fd_id']); + echo ''; + echo '
'; + echo $retour; + echo '
'; +} +//////////////////////////////////////////////////////////////////////////////// +// list +if ( $sub_action == "list" ) +{ +?> +
+ +
+', + $a); +?> + + +
+
+ +
+ + + +name="fd_id"; + $w->value= make_array($cn,"select fd_id,fd_label from fiche_def where ". + " frd_id=".FICHE_TYPE_FOURNISSEUR); + echo $w->IOValue(); +?> + + + +
+
+'; + echo '
'; + echo $sup->Summary($search); + echo '
'; + echo '
'; + echo "Action : Ajout, mise à jour ou effacement"; + echo " "; + + echo '
'; + echo '
'; + +} +//////////////////////////////////////////////////////////////////////////////// +// Show Detail +if ( $sub_action == 'detail' ) +{ + $f_id=$_REQUEST['f_id']; + echo '
'; + $sup=new Supplier($cn,$f_id); + $retour=sprintf('', + urldecode($_REQUEST['url'])); + echo $retour; + echo '
'; + echo $sup->Display(false); + $w=new widget("hidden"); + $w->name="p_action"; + $w->value="fournisseur"; + echo $w->IOValue(); + $w->name="f_id"; + $w->value=$f_id; + echo $w->IOValue(); + + echo $w->Submit('mod','Sauver les modifications'); + echo $w->Reset("Annuler"); + echo $w->Submit('delete','Effacer cette fiche'); + echo '
'; + echo $retour; + echo '
'; +} +html_page_stop(); +?> diff --git a/include/user_form_ach.php b/include/user_form_ach.php index ee3889d74..82ff1f10f 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -61,7 +61,25 @@ echo_debug('user_form_ach.php',__LINE__,"Enter FormAchInput($p_cn,$p_jrn,$p_peri $r.=JS_SEARCH_CARD; $r.=JS_SHOW_TVA; $r.=JS_TVA; - $r.="
"; + // Compute href + $href=$_SERVER['SCRIPT_NAME']; + switch ($href) + { + // user_jrn.php + case '/user_jrn.php': + $href="user_jrn.php?action=new&p_jrn=$p_jrn"; + break; + case '/commercial.php': + $href="commercial.php?p_action=depense&p_jrn=$p_jrn"; + break; + default: + echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri'); + exit (-1); + } + + + // $r.=""; + $r.=""; } $sql="select jrn_def_id as value,jrn_def_name as label from jrn_def where jrn_def_type='VEN'"; @@ -129,7 +147,7 @@ echo_debug('user_form_ach.php',__LINE__,"Enter FormAchInput($p_cn,$p_jrn,$p_peri // Set correctly the REQUEST param for jrn_type $h=new widget('hidden'); $h->name='jrn_type'; - $h->value=$_REQUEST['jrn_type']; + $h->value='ACH'; $r.=$h->IOValue(); // Record the current number of article @@ -569,8 +587,24 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $r.="
"; + // Compute href + $href=$_SERVER['SCRIPT_NAME']; + switch ($href) + { + // user_jrn.php + case '/user_jrn.php': + $href="user_jrn.php?action=new&p_jrn=$p_jrn"; + break; + case '/commercial.php': + $href="commercial.php?p_action=depense&p_jrn=$p_jrn"; + break; + default: + echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri'); + exit (-1); + } - $r.=''; + // $r.=''; + $r.=''; // check for upload piece // Set correctly the REQUEST param for jrn_type $h=new widget('hidden'); @@ -798,7 +832,7 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) Commit($p_cn); - return $comment; + return array($internal,$comment); } ?> diff --git a/include/user_form_ven.php b/include/user_form_ven.php index 5c127778c..bb9710569 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -247,7 +247,7 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ // Set correctly the REQUEST param for jrn_type $h=new widget('hidden'); $h->name='jrn_type'; - $h->value=$_REQUEST['jrn_type']; + $h->value='VEN'; $r.=$h->IOValue(); if ($pview_only == false ) { diff --git a/include/user_menu.php b/include/user_menu.php index 31b7b7ecc..3538e031a 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -266,13 +266,13 @@ function ShowMenuJrnUser($p_dossier,$p_type,$p_jrn,$p_extra="") where uj_login='".$User->id."' and uj_priv !='X' - and jrn_def_type='$p_type' + and jrn_def_type='$p_type' order by jrn_Def_id "); } else { $Ret=ExecSql($Cn,"select jrn_def_id,jrn_def_type,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line, jrn_type_id,jrn_desc,'W' as uj_priv from jrn_def join jrn_type on jrn_def_type=jrn_type_id where - jrn_def_type='$p_type'"); + jrn_def_type='$p_type' order by jrn_Def_id"); } $Max=pg_NumRows($Ret); @@ -297,7 +297,7 @@ function ShowMenuJrnUser($p_dossier,$p_type,$p_jrn,$p_extra="") // p_action=facture if ( $href=="/commercial.php" ) { - $add="&p_action=facture"; + $add='&p_action='.$_REQUEST['p_action']; } echo ''; printf ('%s',