Beta version 2.0 - module de gestion intégré

This commit is contained in:
sparkyx 2006-06-22 22:26:26 +00:00
parent 9703e28ac1
commit f0761196d6
378 changed files with 6932 additions and 346 deletions

390
include/class_action.php Normal file
View file

@ -0,0 +1,390 @@
<?
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.f
require_once("class_fiche.php");
require_once("class_document.php");
require_once("class_document_type.php");
require_once("user_common.php");
/*!\file
* \brief class_action for manipulating actions
* action can be :
* - an invoice
* - a meeting
* - an order
* - a letter
*
* The table document_type are the possible actions
*/
/*!
* \brief class_action for manipulating actions
* action can be :
* - an invoice
* - a meeting
* - an order
* - a letter
*
* The table document_type are the possible actions
*/
class action
{
/*! \enum $db database connexion
* \enum $ag_desc description (ag_gestion.ag_desc)
* \enum $ag_date document date (ag_gestion.ag_date)
* \enum $dt_id type of the document (document_type.dt_id)
* \enum $d_state stage of the document (printed, send to client...)
* \enum $d_number number of the document
* \enum $d_filename filename's document
* \enum $d_mimetype document's filename
* \enum $ag_title title document
* \enum $f_id fiche id
*/
var $db;
var $ag_desc;
var $ag_date;
var $d_lob;
var $dt_id;
var $d_state;
var $d_number;
var $d_filename;
var $d_mimetype;
var $ag_title;
var $f_id;
/*! constructor
* \brief constructor
* \param p_cn database connection
*/
function action ($p_cn)
{
$this->db=$p_cn;
$this->f_id=0;
}
/*! Display
* \brief Display the object
*
* \return string containing the html code
*/
function Display()
{
$r="";
// Compute the widget
// Date
$date=new widget("text");
$date->readonly=true;
$date->name="ag_date";
$date->value=$this->ag_date;
// Doc Type
$doc_type=new widget("hidden");
$doc_type->name="dt_id";
$doc_type->value=$this->dt_id;
$a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
$v=pg_fetch_array($a,0);
$str_type=$v[0];
// state
// Retrieve the value
$a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
$v=pg_fetch_array($a,0);
$str_state=$v[0];
$state=new widget("hidden");
$state->name="d_state";
$state->value=$this->d_state;
// title
$title=new widget("text");
$title->readonly=true;
$title->name="ag_title";
$title->value=FormatString($this->ag_title);
// Description
$desc=new widget('textarea');
$desc->name="ag_desc";
$desc->readonly=" disabled ";
$desc->value=$this->ag_desc;
// Propose to generate a document
$gen=new widget ("checkbox");
$gen->name="p_gen";
$doc_gen=new widget("select");
$doc_gen->name="gen_doc";
$doc_gen->value=make_array($this->db,
"select md_id,md_name from document_modele where md_type=".$this->dt_id);
// f_id
$tiers=new fiche($this->db);
$tiers->GetByQCode($this->qcode);
// Preparing the return string
$r.="<p>Date : ".$date->IOValue()."</p>";
$r.="<p>Etat $str_state".$state->IOValue()."</p>";
$r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
$r.="<p> Tiers : ".$this->qcode." ".$tiers->strAttribut(1).'</p>';
$r.="<p> Titre : ".$title->IOValue();
$r.="<p>Description :".urldecode($desc->IOValue())."</p>";
return $r;
}
/*! Confirm
* \brief Display the encoded data and ask a confirmation
* this correspond to the stage 1, before the generation
* or the upload of document
*
*
* \return string containing the form
*/
function Confirm()
{
if ( isDate($this->ag_date) == NULL )
{
// if the date is invalid, default date is today
$this->ag_date=date("d.m.Y");
}
// Compute the widget
// Date
$date=new widget("text");
$date->readonly=true;
$date->name="ag_date";
$date->value=$this->ag_date;
// Doc Type
$doc_type=new widget("hidden");
$doc_type->name="dt_id";
$doc_type->value=$this->dt_id;
$a=ExecSql($this->db,"select dt_value from document_type where dt_id=".$this->dt_id);
$v=pg_fetch_array($a,0);
$str_type=$v[0];
if ( isset ($_REQUEST['url']))
{
$retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
$h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
}
else
{
$retour="";
$h_url="";
}
// state
// Retrieve the value
$a=ExecSql($this->db,"select s_value from document_state where s_id=".$this->d_state);
$v=pg_fetch_array($a,0);
$str_state=$v[0];
$state=new widget("hidden");
$state->name="d_state";
$state->value=$this->d_state;
// title
$title=new widget("text");
$title->readonly=true;
$title->name="ag_title";
$title->value=FormatString($this->ag_title);
// Description
$desc=new widget('textarea');
$desc->name="ag_desc";
$desc->readonly=" disabled ";
$desc->value=$this->ag_desc;
// Propose to generate a document
$gen=new widget ("checkbox");
$gen->name="p_gen";
$doc_gen=new widget("select");
$doc_gen->name="gen_doc";
$doc_gen->value=make_array($this->db,
"select md_id,md_name from document_modele where md_type=".$this->dt_id);
// f_id
$tiers=new fiche($this->db);
$tiers->GetByQCode($this->qcode);
// Preparing the return string
$r=$retour."<form method=\"post\">";
$r.="<p>Date : ".$date->IOValue()."</p>";
$r.="<p>Etat $str_state".$state->IOValue()."</p>";
$r.="<p>Type du document $str_type".$doc_type->IOValue()."</p>";
$r.="<p> Tiers : ".$this->qcode." ".$tiers->strAttribut(1).'</p>';
$r.="<p> Titre : ".$title->IOValue();
$r.="<p>Description :".$desc->IOValue()."</p>";
// if no document exist for this type then do not display the question
if ( sizeof($doc_gen->value) != 0)
$r.="<p> G&eacute;n&eacute;rer un document ".$gen->IOValue()." ".$doc_gen->IOValue()."</p>";
// Add the hidden tag
$r.='<input type="hidden" name="sa" value="save_action_st2">';
$r.='<input type="hidden" name="p_action" value="suivi_courrier">';
$r.='<input type="hidden" name="tiers" value="'.$this->qcode.'">';
if ( $tiers->strAttribut(1) != "- ERROR -")
$r.=$desc->Submit("Save","Sauve");
$r.=$desc->Submit("corr","Corrige");
$r.=$h_url."</form>";
return $r;
}
/*! SaveStage2
* \brief Save the document and propose to save the generated document or
* to upload one, the data are included except the file. Temporary the generated
* document is save
*
* \return
*/
function SaveStage2()
{
// Get The sequence id,
$seq_name="seq_doc_type_".$this->dt_id;
$str_file="";
$add_file='';
// f_id
$tiers=new fiche($this->db);
$tiers->GetByQCode($this->qcode);
if ( trim($this->ag_title) == "") {
$doc_mod=new document_type($this->db);
$doc_mod->dt_id=$this->dt_id;
$doc_mod->get();
$this->ag_title=$doc_mod->dt_value;
}
echo_debug('class_action',__LINE__," tiers->id ".$tiers->id);
$sql=sprintf("insert into action_gestion(ag_type,ag_title,f_id,ag_comment) values ('%s','%s',%d,'%s')", $this->dt_id,
FormatString($this->ag_title),
$tiers->id,
FormatString(urlencode($this->ag_desc)));
ExecSql($this->db,$sql);
$this->ag_id=GetSequence($this->db,'action_gestion_ag_id_seq');
// the lob filename and the mimetype needed if we want to generate a doc.
if ( $this->gen == 'on' )
{
$doc=new Document($this->db);
$doc->f_id=$tiers->id;
$doc->md_id=$this->md_id;
$doc->ag_id=$this->ag_id;
$str_file=$doc->Generate();
}
$r=$this->Display();
$r.="<hr>";
$r.='<form enctype="multipart/form-data" method="post">';
// Add the hidden tag
$r.='<input type="hidden" name="sa" value="save_action_st3">';
$r.='<input type="hidden" name="p_action" value="suivi_courrier">';
$r.='<input type="hidden" name="ag_id" value="'.$this->ag_id.'">';
// Value for the generated document
if ( $this->gen == 'on' )
{
$r.='<input type="hidden" name="d_id" value="'.$doc->d_id.'">';
$r.="Sauver le document généré :";
$r.=$str_file;
$checkbox=new widget("checkbox");
$checkbox->name="save_generate";
$r.=$checkbox->IOValue();
$r.="<hr>";
}
$upload=new widget("file");
$upload->name="file_upload";
$upload->value="";
$r.="Enregistrer le fichier ".$upload->IOValue();
$r.=$upload->Submit("save","Sauve le fichier");
$r.="</form>";
return $r;
}
/*! SaveStage3
* \brief Upload the document or save the generated document
* \param $d_id document_id when we upload we don't increment seq. if = 0 then no file
*
*/
function SaveStage3($d_id)
{
// no generated doc
if ( $d_id == 0 ) return;
// if we save the generated doc
if ( isset($_POST['save_generate']))
{
return;
}
// Upload a new document
$doc=new Document($this->db);
$doc->d_id=$d_id;
$doc->Upload($this->ag_id);
}
/*! myList($p_filter="")
* \brief Show list of action
* \param $p_filter filters on the document_type
* \param $p_search must a valid sql command ( ex 'and ag_title like upper('%hjkh%'))
*
*
* \return string containing html code
*/
function myList($p_filter="",$p_search="")
{
$sql="
select ag_id,to_char(ag_timestamp,'DD-MM-YYYY HH:MI') as my_date,f_id,ag_title,d_id,md_type,dt_value
from action_gestion
left outer join document using (ag_id)
left outer join document_modele on (ag_type=md_type)
join document_type on (ag_type=dt_id)
where dt_id in ($p_filter) $p_search";
$max_line=CountSql($this->db,$sql);
$step=$_SESSION['g_pagesize'];
$page=(isset($_GET['offset']))?$_GET['page']:1;
$offset=(isset($_GET['offset']))?$_GET['offset']:0;
$limit=" LIMIT $step OFFSET $offset ";
$bar=jrn_navigation_bar($offset,$max_line,$step,$page);
$Res=ExecSql($this->db,$sql.$limit);
$a_row=pg_fetch_all($Res);
$r='<div class="u_redcontent">';
$r.=$bar;
$r.="<table>";
$r.="<tr>";
$r.="<th>Date</th>";
$r.="<th>Société</th>";
$r.="<th>Titre</th>";
$r.="<th>type</th>";
$r.="<th>Document</th>";
$r.="</tr>";
// if there are no records return a message
if ( sizeof ($a_row) == 0 or $a_row == false )
{
$r='<div class="u_redcontent">';
$r.='<hr>Aucun enregistrement trouvé';
$r.="</div>";
return $r;
}
foreach ($a_row as $row )
{
$r.="<tr>";
$r.="<td>".$row['my_date']."</td>";
$f=new fiche($this->db);
$f->id=$row['f_id'];
$r.="<td>".$f->getName()."</td>";
$r.="<td>".$row['ag_title']."</td>";
$r.="<td>".$row['dt_value']."</td>";
$doc=new Document($this->db,$row['d_id']);
$r.="<td>".$doc->a_ref()."</td>";
$r.="</tr>";
}
$r.="</table>";
$r.=$bar;
$r.="</div>";
return $r;
}
}

129
include/class_contact.php Normal file
View file

@ -0,0 +1,129 @@
<?
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
//!\brief class for the contact, contact are derived from fiche
require_once("class_fiche.php");
require_once("constant.php");
require_once("user_common.php");
/*! \file
* \brief Contact are a card which are own by a another card (customer, supplier...)
*/
/*!
* \brief Class contact (customer, supplier...)
*/
class contact extends fiche
{
var $company; /*!\enum $company company of the contact (ad_id=ATTR_DEF_COMPANY)*/
/*!\brief constructor */
function contact($p_cn,$p_id=0)
{
$this->fiche_def_ref=FICHE_TYPE_CONTACT;
fiche::fiche($p_cn,$p_id) ;
$this->company="";
}
/*! Summary
**************************************************
* \brief show the default screen
*
* \param p_search (filter)
*
* \return string to display
*/
function Summary($p_search)
{
$p_search=FormatString($p_search);
$extra_sql="";
if ( $this->company != "")
{
$extra_sql="and f_id in (select f_id from jnt_fic_att_value join
attr_value using (jft_id) where av_text='".$this->company."' and ad_id=".ATTR_DEF_COMPANY.") ";
}
$url=urlencode($_SERVER['REQUEST_URI']);
$script=$_SERVER['SCRIPT_NAME'];
// Creation of the nav bar
// Get the max numberRow
$all_contact=$this->CountByDef($this->fiche_def_ref,$p_search,$extra_sql);
// 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_contact,$_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_contact=$this->GetAll($offset,$search.$extra_sql);
if ( $all_contact == 0 ) return "";
$r=$bar;
$r.='<table>
<TR style="background-color:lightgrey;">
<th>Nom</th>
<th>Téléphone</th>
<th>email</th>
<th>Fax</th>
<th>Société</th>
</TR>';
$base=$_SERVER['SCRIPT_NAME'];
// Compute the url
$url="";
$and="?";
$get=$_GET;
if ( isset ($get) ) {
foreach ($get as $name=>$value ) {
// we clean the parameter offset, step, page and size
if ( ! in_array($name,array('f_id','detail'))) {
$url.=$and.$name."=".$value;
$and="&";
}// if
}//foreach
}// if
if ( sizeof ($step_contact ) == 0 )
return $r;
foreach ($step_contact as $contact ) {
$l_company=new fiche($this->cn);
$l_company->GetByQCode($contact->strAttribut(ATTR_DEF_COMPANY),false);
$l_company_name=$l_company->strAttribut(ATTR_DEF_NAME);
if ( $l_company_name == '- ERROR -' ) $l_company_name="";
$r.="<TR>";
$r.='<TD><A HREF="'.$url."&sa=detail&f_id=".$contact->id."\">".$contact->strAttribut(ATTR_DEF_NAME)."</A></TD>";
$r.="<TD>".$contact->strAttribut(ATTR_DEF_TEL)."</TD>";
$r.="<TD>".$contact->strAttribut(ATTR_DEF_EMAIL)."</TD>".
"<TD> ".$contact->strAttribut(ATTR_DEF_FAX)."</TD>".
"<TD> ".$l_company_name.
"</TD>";
$r.="</TR>";
}
$r.="</TABLE>";
$r.=$bar;
return $r;
}
}

View file

@ -0,0 +1,52 @@
<?
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief class for the table document_type
*/
/*! \brief class for the table document_type
* \enum dt_id pk document_type
* \enum dt_value value
*/
class Document_type
{
/*! document_type
* \brief constructor
* \param $p_cn database connx
*/
function document_type($p_cn)
{
$this->db=$p_cn;
$this->dt_id=-1;
}
/*!
* \brief Get all the data for this dt_id
*/
function get()
{
$sql="select * from document_type where dt_id=".$this->dt_id;
$R=ExecSql($this->db,$sql);
$r=pg_fetch_array($R,0);
$this->dt_id=$r['dt_id'];
$this->dt_value=$r['dt_value'];
}
}

151
include/class_invoice.php Normal file
View file

@ -0,0 +1,151 @@
<?
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief Class invoice to manage the customer invoice
* \todo obsolete ? then delete it
*/
/*!
* \brief Class invoice to manage the customer invoice
*
*/
class Invoice {
var $cn; /*! \enum $cn database conx */
var $id; /*! \enum $id iv_id */
var $template; /*! \enum $template template's name */
//Constructor parameter = database connexion
function Invoice($p_cn) {
$this->cn=$p_cn;
}
// show the stored invoice template
function myList() {
$sql="select iv_id,iv_name from invoice";
$Res=ExecSql($this->cn,$sql);
$all=pg_fetch_all($Res);
if ( pg_NumRows($Res) == 0 ) return "";
foreach ( $all as $row) {
var_dump($row);
}
}
// Save a template in the database
function Save() {
// Values are in $_POST
StartSql($this->cn);
// Save data into the table invoice
// Save the file
$new_name=tempnam('/tmp','invoice_');
echo_debug('class_invoice.php',__LINE__,"new name=".$new_name);
if ( strlen ($_FILES['pj']['tmp_name']) != 0 )
{
if (move_uploaded_file($_FILES['invoice']['tmp_name'],
$new_name))
{
// echo "Image saved";
$oid= pg_lo_import($this->cn,$new_name);
if ( $oid == false )
{
echo_error('class_invoice.php',__LINE__,"cannot upload document");
Rollback($cn);
return;
}
echo_debug('class_invoice.php',__LINE__,"Loading document");
// Remove old document
$ret=ExecSql($this->cn,"select iv_file from invoice where iv_id=".$this->id);
if (pg_num_rows($ret) != 0)
{
$r=pg_fetch_array($ret,0);
$old_oid=$r['iv_file'];
if (strlen($old_oid) != 0)
pg_lo_unlink($this->cn,$old_oid);
}
// Load new document
ExecSql($this->cn,"update invoice set iv_file where iv_id=".$this->id);
}
else
{
echo "<H1>Error</H1>";
Rollback($this->cn);
exit;
}
}
}
// Remove a template
function Delete() {
}
// return the string containing the form for
// adding a template
function FormAdd() {
$r="";
$r='<FORM METHOD="POST" ACTION="dossier_prefs.php">';
$r.="</FORM>";
return $r;
}
// return the string containing the form for
// removing a template
function FormDelete() {
}
// Parse and remplace the tag in the invoice
// By the value found in quant_sold
// p_id is the id of the invoice
// p_internal reference (quant_sold qs_internal)
function Get($p_id,$p_internal)
{
// retrieve info from the table invoice
// retrieve the template and generate document
StartSql($this->cn);
$ret=ExecSql($cn,"select iv_name,iv_file from invoice where iv_id".$this->iv_id);
if ( pg_num_rows ($ret) == 0 )
return;
$row=pg_fetch_array($ret,0);
//the template is saved into file $tmp
$tmp=tempnam('/tmp/','invoice_');
pg_lo_export($cn,$row['iv_file'],$tmp);
// Parse the file
// send it to stdout
ini_set('zlib.output_compression','Off');
header("Pragma: public");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate");
header('Content-type: rtf/x-application');
header('Content-Disposition: attachment;filename="invoice'.$p_internal.'.rtf"',FALSE);
header("Accept-Ranges: bytes");
$file=fopen($tmp,'r');
while ( !feof ($file) )
{
echo fread($file,8192);
}
fclose($file);
unlink ($tmp);
Commit($cn);
}
}
?>

191
include/contact.inc.php Normal file
View file

@ -0,0 +1,191 @@
<?
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
//!\brief File for adding contact, contact is a kind of fiche
require_once('class_contact.php');
require_once('class_widget.php');
/*! \file
* \brief the contact class is derived from the class fiche
* the contact is in fact a card but more specific
* This file is included from the module "Gestion"
*/
$sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
var_dump($_REQUEST);
// if this page is called from another menu (customer, supplier,...)
// a button back is added
// TODO add function for generating url, hidden tags...
if ( isset ($_REQUEST['url']))
{
$retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
$h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
}
else
{
$retour="";
$h_url="";
}
// Menu
// Remove a card
if ( isset ($_POST['delete']) )
{
echo 'delete';
$f_id=$_REQUEST['f_id'];
$fiche=new contact($cn,$f_id);
$fiche->remove();
$sub_action="list";
}
////////////////////////////////////////////////////////////////////////////////
// Add card
if ( $sub_action=="insert" )
{
$contact=new Contact($cn);
$contact->Save($_REQUEST['fd_id']);
echo $retour;
echo "<table>";
echo $contact->Display(true);
echo "</table>";
echo $retour;
}
////////////////////////////////////////////////////////////////////////////////
// Save modification
if ( isset ($_POST['mod']))
{
// modification is asked
$f_id=$_REQUEST['f_id'];
$contact=new contact($cn,$f_id);
$contact->Save();
}
// by default open liste
if ( $sub_action == "" )
$sub_action="list";
////////////////////////////////////////////////////////////////////////////////
//Display a blank card
if ( $sub_action=="blank")
{
$retour=sprintf('<A class="two" HREF="%s"><input type="button" value="Retour"></A>',
"commercial.php?p_action=contact");
echo '<div class="u_redcontent">';
echo $retour;
$c=new contact($cn);
echo '<form method="post" action="commercial.php"';
echo '<input type="hidden" name="p_action" value="client">';
echo '<input type="hidden" name="sa" value="insert">';
echo '<input type="hidden" name="fd_id" value="'.$_GET['fd_id'].'">';
echo '<input type="hidden" name="url" value="'.$_GET['url'].'">';
echo $c->blank($_GET['fd_id']);
echo '<input type="Submit" value="Sauve">';
echo '</form>';
echo $retour;
echo '</div>';
}
////////////////////////////////////////////////////////////////////////////////
// list
if ( $sub_action == "list" )
{
?>
<div class="u_content">
<span>
<form method="get" action="commercial.php">
<?
$a=(isset($_GET['query']))?$_GET['query']:"";
printf ('<input type="text" name="query" value="%s">',
$a);
?>
<input type="submit" name="submit_query" value="recherche">
<input type="hidden" name="p_action" value="contact">
</form>
</span>
<span>
<form method="get" action="commercial.php">
<input type="hidden" name="url" <? $url=urlencode($_SERVER['REQUEST_URI']);echo 'value="'.$url.'"'; ?>
<input type="hidden" name="p_action" value="contact">
<?
$w=new widget("select");
$w->name="fd_id";
$w->value= make_array($cn,"select fd_id,fd_label from fiche_def where ".
" frd_id=".FICHE_TYPE_CONTACT);
echo $w->IOValue();
?>
<input type="hidden" name="sa" value="blank">
<input type="submit" name="submit_query" value="Ajout Contact">
</form>
</span>
<form>
<?
$qcode=(isset($_GET['qcode']))?$_GET['qcode']:"";
printf ('<span>Tiers QuickCode: <input type="text" name="qcode" value="%s"></span>',
$qcode);
?>
<input type="submit" name="submit_query" value="recherche">
<input type="hidden" name="p_action" value="contact">
</FORM>
<?
$contact=new Contact($cn);
$search=(isset($_GET['query']))?$_GET['query']:"";
// check if a company is asked if yes, add a condition
if ( $qcode != "" )
{
$contact->company=$qcode;
}
echo '<div class="u_redcontent">';
echo $contact->Summary($search);
echo '</div>';
}
////////////////////////////////////////////////////////////////////////////////
// Show Detail
if ( $sub_action == 'detail' )
{
$f_id=$_REQUEST['f_id'];
echo '<div class="u_redcontent">';
$contact=new contact($cn,$f_id);
echo $retour;
echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">';
echo $contact->Display(false);
$w=new widget("hidden");
$w->name="p_action";
$w->value="contact";
echo $w->IOValue();
$w->name="f_id";
$w->value=$f_id;
echo $w->IOValue();
echo $w->Submit('mod','Sauver les modifications');
echo '<A HREF="commercial.php?p_action=contact"><INPUT TYPE="button" value="Retour"></A>';
echo $w->Submit('delete','Effacer cette fiche');
echo '</form>';
echo $retour;
echo '<div>';
}
html_page_stop();

241
include/facture.inc.php Normal file
View file

@ -0,0 +1,241 @@
<?
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
require_once('class_jrn.php');
require_once('user_form_ven.php');
require_once('jrn.php');
require_once("class_document.php");
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);
// First we show the menu
// 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;
} else
{
$p_jrn=$_REQUEST['p_jrn'];
}
// for the back button
if ( isset ($_REQUEST['url']))
{
$retour=sprintf('<A HREF="%s"><input type="button" value="Retour"></A>',urldecode($_REQUEST['url']));
$h_url=sprintf('<input type="hidden" name="url" value="%s">',urldecode($_REQUEST['url']));
}
else
{
$retour="";
$h_url="";
}
$sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
////////////////////////////////////////////////////////////////////////////////
// If a list of invoice is asked
//
if ( $sub_action == "list")
{
// show the menu with the list item selected
echo '<div class="u_subtmenu">';
echo ShowMenuJrnUser($_SESSION['g_dossier'],'VEN',$p_jrn,'<td class="selectedcell">Liste</td>');
echo '</div>';
// 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 '<div class="u_redcontent">';
echo '<form method= "GET" action="commercial.php">';
$hid=new widget("hidden");
$hid->name="p_action";
$hid->value="facture";
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 ('<span>Tiers QuickCode: <input type="text" name="qcode" value="%s"></span>',
$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'" ;
$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='VEN' and jr_tech_per=$current $l "
,null,$offset,1);
$bar=jrn_navigation_bar($offset,$max_line,$step,$page);
echo "<hr> $bar";
echo $list;
echo "$bar <hr>";
if ( $max_line !=0 )
echo $hid->Submit('paid','Mise à jour paiement');
echo '</FORM>';
echo '</div>';
exit();
}
////////////////////////////////////////////////////////////////////////////////
echo '<div class="u_subtmenu">';
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>');
echo '</div>';
////////////////////////////////////////////////////////////////////////////////
// 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++;
$form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,false,$nb_item);
echo '<div class="u_redcontent">';
echo $form;
echo '</div>';
exit();
}
////////////////////////////////////////////////////////////////////////////////
// we want to save the invoice and to generate a invoice
//
if ( isset($_POST['record_and_print_invoice']))
{
// First we save the invoice
RecordInvoice($cn,$_POST,$User,$p_jrn);
$form=FormVenteView($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,$_POST['nb_item'],'noform','');
// $form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,true,$_POST['nb_item']);
echo '<div class="u_redcontent">';
echo $form;
echo '<hr>';
// Show the details of the encoded invoice
// and the url of the invoice
if ( isset($_POST['gen_invoice']))
{
$doc=new Document($cn);
$doc->f_id=$_POST['e_client'];
$doc->md_id=$_POST['gen_doc'];
$doc->ag_id=0;
$str_file=$doc->Generate();
echo $str_file;
}
echo '</form>';
exit();
}
////////////////////////////////////////////////////////////////////////////////
// we show the confirmation screen it is proposed here to generate the
// invoice
if ( isset ($_POST['view_invoice']) )
{
$nb_number=$_POST["nb_item"];
if ( form_verify_input($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,$nb_number) == true)
{
$form=FormVenteView($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,$nb_number);
} else {
// Check failed : invalid date or quantity
echo_error("Cannot validate ");
$form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,false,$nb_number);
}
echo '<div class="u_redcontent">';
echo $form;
echo '</div>';
exit();
}
////////////////////////////////////////////////////////////////////////////////
// By default we add a new invoice
if ( $p_jrn != -1 )
{
$jrn=new jrn($cn, $p_jrn);
echo_debug('user_action_ven.php',__LINE__,"Blank form");
// Show an empty form of invoice
$form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),null,false,$jrn->GetDefLine('cred'));
echo '<div class="u_redcontent">';
echo $form;
echo '</div>';
}