diff --git a/html/bal_csv.php b/html/bal_csv.php index b5a500c54..7494fc788 100644 --- a/html/bal_csv.php +++ b/html/bal_csv.php @@ -29,7 +29,7 @@ include_once ("postgres.php"); require_once('class_dossier.php'); $gDossier=dossier::id(); -include("class_jrn.php"); +include("class_acc_ledger.php"); $cn=DbConnect($gDossier); diff --git a/html/ca_list_pdf.php b/html/ca_list_pdf.php index 3b0fac489..ff17d4a23 100644 --- a/html/ca_list_pdf.php +++ b/html/ca_list_pdf.php @@ -28,10 +28,10 @@ */ require_once('constant.php'); require_once('postgres.php'); -require_once('class_operation.php'); +require_once('class_anc_operation.php'); $cn=DbConnect(dossier::id); -$op=new operation($cn); +$op=new Anc_Operation($cn); $op->pa_id=$_GET['pa_id']; $array=$op->get_list($_GET['from'],$_GET['to']); $length=count($array); diff --git a/html/caop_detail.php b/html/caop_detail.php index bf8d6dfdb..10cdf667f 100644 --- a/html/caop_detail.php +++ b/html/caop_detail.php @@ -4,8 +4,8 @@ header("Content-type: text/xml charset=\"ISO8859-1\"",true); require_once ('postgres.php'); require_once ('debug.php'); require_once ('jrn.php'); -require_once ('class_operation.php'); +require_once ('class_anc_operation.php'); $cn=DbConnect($_SESSION['g_dossier']); -$op=new operation($cn); +$op=new Anc_Operation($cn); $op->get_xml_jrn_detail(); ?> diff --git a/html/commercial.php b/html/commercial.php index 96bb0a1b4..a06cbed57 100644 --- a/html/commercial.php +++ b/html/commercial.php @@ -91,6 +91,7 @@ echo ShowItem(array( array('?p_action=facture&'.$str_dossier,'Vente/Facture'), array('?p_action=fournisseur&'.$str_dossier,'Fournisseur'), array('?p_action=depense&'.$str_dossier,'Achat/Dépense'), + array('?p_action=quick_writing&'.$str_dossier,'Ecriture rapide'), array('?p_action=impress&'.$str_dossier,'Impression'), array('?p_action=stock&'.$str_dossier,'Stock'), array('?p_action=bank&'.$str_dossier,'Banque'), @@ -167,6 +168,10 @@ if ( $p_action == 'bank') { require_once("bank.inc.php"); } +if ( $p_action=='quick_writing') { + require_once ('quick_writing.inc.php'); + } + //----------------------------------------------------- // Impression if ( $p_action == 'impress') diff --git a/html/compta.php b/html/compta.php index 81c3625d5..82f22a925 100644 --- a/html/compta.php +++ b/html/compta.php @@ -63,6 +63,8 @@ if ( $action == 'fiche') { if ( $action == 'stock') { require_once('stock.inc.php'); } - +if ( $action=='quick_writing') { + require_once ('quick_writing.inc.php'); + } html_page_stop(); ?> diff --git a/html/fiche_new.php b/html/fiche_new.php index 0c6f01089..f62914c74 100644 --- a/html/fiche_new.php +++ b/html/fiche_new.php @@ -90,7 +90,7 @@ if ( isset($_POST['add_fiche'])) { // Prob : ajout de fiche mais si plusieur cat possible ??? // Get the field from database // if e_type contains a list of value - if ( $e_type != 'cred' and $e_type != 'deb') { + if ( $e_type != 'cred' and $e_type != 'deb' && $e_type!='filter') { // $list['fiche']=$e_type; $sql="select fd_id from fiche_def where frd_id in ($e_type)"; $Res=ExecSql($cn,$sql); @@ -115,7 +115,16 @@ if ( isset($_POST['add_fiche'])) { $get='jrn_def_fiche_cred'; $sql="select $get as fiche from jrn_def where jrn_def_id=".$_GET['p_jrn']; } + if ($e_type=='filter') { + $get_cred='jrn_def_fiche_cred'; + + $get_deb='jrn_def_fiche_deb'; + + $sql="select $get_cred||','||$get_deb as fiche from jrn_def where jrn_def_id=".$_GET['p_jrn']; + + } + $Res=ExecSql($cn,$sql); diff --git a/html/fiche_search.php b/html/fiche_search.php index 8feedcb71..9862f97ef 100644 --- a/html/fiche_search.php +++ b/html/fiche_search.php @@ -131,12 +131,29 @@ if ( elseif ( $e_type == 'all' ) { $sql="select * from vw_fiche_attr where true"; } + elseif ($e_type=='filter') { + + $get='jrn_def_fiche_cred'; + $list_cred=get_list_fiche($cn,$get,$_GET['p_jrn']); + + + $get='jrn_def_fiche_deb'; + $list_deb=get_list_fiche($cn,$get,$_GET['p_jrn']); + $list_fiche=$list_cred.','.$list_deb; + + if ( $list_fiche == ',' ) + exit("Vous n'avez pas bien configure ce journal, vous devez aller dans Avance->Journal et indiquez les fiches utilisables"); + + $sql="select * from vw_fiche_attr where fd_id in ( $list_fiche )"; + + } // if e_type contains a list of value for filtering on fiche_def_ref.frd_id else{ $list_fiche=$e_type; $sql="select * from vw_fiche_attr where frd_id in ( $list_fiche )"; // $sql="select * from vw_fiche_attr "; } + // e_fic_search contains the pattern if (strlen(trim($e_fic_search) ) == 0 ) { diff --git a/html/fid.php b/html/fid.php index d9f862b04..3c44327d2 100644 --- a/html/fid.php +++ b/html/fid.php @@ -27,6 +27,15 @@ if ( isset($_SESSION['isValid']) && $_SESSION['isValid'] == 1) case 'all': $filter_card=""; break; + case 'filter': + $get_cred='jrn_def_fiche_cred'; + + $get_deb='jrn_def_fiche_deb'; + + $filter_jrn=Getdbvalue($cn,"select $get_cred||','||$get_deb as fiche from jrn_def where jrn_def_id=$jrn"); + + $filter_card="and fd_id in ($filter_jrn)"; + break; default: $filter_card="and frd_id in ($d)"; } diff --git a/html/jrn_csv.php b/html/jrn_csv.php index 12e8dd0e1..be0f4069b 100644 --- a/html/jrn_csv.php +++ b/html/jrn_csv.php @@ -31,7 +31,7 @@ $gDossier=dossier::id(); include_once ("postgres.php"); include_once("check_priv.php"); -include("class_jrn.php"); +include("class_acc_ledger.php"); $cn=DbConnect($gDossier); $rep=DbConnect(); @@ -47,7 +47,7 @@ if ( $User->CheckAction($cn,IMP) == 0 || $p_cent=( isset ( $_GET['central']) )?$_GET['central']:'off'; -$Jrn=new jrn($cn,$_GET['jrn_id']); +$Jrn=new Acc_Ledger($cn,$_GET['jrn_id']); $Jrn->GetName(); $jrn_type=$Jrn->get_type(); diff --git a/html/jrn_pdf.php b/html/jrn_pdf.php index d3cf9d37d..cbf807208 100644 --- a/html/jrn_pdf.php +++ b/html/jrn_pdf.php @@ -35,7 +35,7 @@ include_once("postgres.php"); include_once("class.ezpdf.php"); include_once("impress_inc.php"); include_once("preference.php"); -include_once("class_jrn.php"); +include_once("class_acc_ledger.php"); include_once("check_priv.php"); require_once ('header_print.php'); @@ -48,7 +48,7 @@ if ($_GET['central'] == 'on' ) { $centr=" centralisé "; $l_centr=1; } -$Jrn=new jrn($cn,$_GET['jrn_id']); +$Jrn=new Acc_Ledger($cn,$_GET['jrn_id']); $Jrn->GetName(); $User=new cl_user(DbConnect()); diff --git a/html/modify_op.php b/html/modify_op.php index bb72d290f..44257e355 100644 --- a/html/modify_op.php +++ b/html/modify_op.php @@ -233,23 +233,23 @@ if ( isset($_POST['update_record']) ) { if ( $own->MY_ANALYTIC == "ob") { $tab=0; $row=1; while (1) { - if ( !isset ($_POST['nb_t'.$tab])) - break; - $tot_tab=0; - - for ($i_row=0;$i_row <= MAX_COMPTE;$i_row++) { - if ( ! isset($_POST['val'.$tab.'l'.$i_row])) - continue; - $tot_tab+=$_POST['val'.$tab.'l'.$i_row]; - } - print_r ( "\$tot_tab $tot_tab \$_POST['amount_t'.$tab ".$_POST['amount_t'.$tab]); - if ( $tot_tab != $_POST['amount_t'.$tab]) { - echo "Erreur montant CA"; - echo "Opération annulée"; - return; - } - $tot_tab=0; - $tab++; + if ( !isset ($_POST['nb_t'.$tab])) + break; + $tot_tab=0; + + for ($i_row=0;$i_row <= MAX_COMPTE;$i_row++) { + if ( ! isset($_POST['val'.$tab.'l'.$i_row])) + continue; + $tot_tab+=$_POST['val'.$tab.'l'.$i_row]; + } + print_r ( "\$tot_tab $tot_tab \$_POST['amount_t'.$tab ".$_POST['amount_t'.$tab]); + if ( $tot_tab != $_POST['amount_t'.$tab]) { + echo "Erreur montant CA"; + echo "Opération annulée"; + return; + } + $tot_tab=0; + $tab++; } } @@ -269,7 +269,7 @@ if ( isset($_POST['update_record']) ) { echo_debug(__FILE__.':'.__LINE__,"array is ",$row_ca); if ( ereg("^[6,7]+",$row_ca['j_poste'])) { echo_debug(__FILE__.':'.__LINE__,"count is ",$count); - $op=new operation($cn); + $op=new Anc_Operation($cn); $op->delete_by_jid($row_ca['j_id']); $op->j_id=$row_ca['j_id']; $op->oa_debit=$row_ca['j_debit']; diff --git a/include/bank.inc.php b/include/bank.inc.php index d3493421b..13fb12a9f 100644 --- a/include/bank.inc.php +++ b/include/bank.inc.php @@ -18,7 +18,7 @@ */ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr -require_once('class_jrn.php'); +require_once('class_acc_ledger.php'); require_once('user_form_fin.php'); require_once('jrn.php'); require_once("class_document.php"); @@ -335,7 +335,7 @@ if ( $p_jrn != -1 ) exit -1; } - $jrn=new jrn($cn, $p_jrn); + $jrn=new Acc_Ledger($cn, $p_jrn); echo_debug('depense.inc.php',__LINE__,"Blank form"); // Submit button in the form $submit=' diff --git a/include/ca_imp.inc.php b/include/ca_imp.inc.php index 10057acde..d15bd8f11 100644 --- a/include/ca_imp.inc.php +++ b/include/ca_imp.inc.php @@ -27,7 +27,7 @@ * accountancy. * */ -require_once('class_operation.php'); +require_once('class_anc_operation.php'); require_once('class_plananalytic.php'); require_once('ac_common.php'); require_once('class_widget.php'); diff --git a/include/ca_od.inc.php b/include/ca_od.inc.php index f60de152a..ab4f0199c 100644 --- a/include/ca_od.inc.php +++ b/include/ca_od.inc.php @@ -28,7 +28,7 @@ */ require_once("class_poste_analytic.php"); require_once ("class_widget.php"); -require_once ("class_operation.php"); +require_once ("class_anc_operation.php"); require_once ("class_groupop.php"); @@ -66,7 +66,7 @@ if ( isset($_GET['see'])) { // and exit //----------------------------- echo JS_AJAX_OP; - $a=new operation($cn); + $a=new Anc_Operation($cn); echo '
@@ -118,7 +118,7 @@ if ( isset($_POST['save'])) { } if ( isset($_GET['new'])) { - //show the form for entering a new operation + //show the form for entering a new Anc_Operation //------------------------------------------ $a=new groupop($cn); diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index b8f00a63f..c92299703 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -19,19 +19,31 @@ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr require_once('class_fiche.php'); +require_once('class_user.php'); +require_once ('class_widget.php'); +require_once ('class_dossier.php'); +require_once ('class_own.php'); +require_once ('class_anc_operation.php'); +require_once ('class_acc_operation.php'); +require_once ('class_poste.php'); +require_once ('class_pre_op_advanced.php'); +require_once ('jrn.php'); /*!\brief Class for jrn * */ -class jrn { +class Acc_Ledger { var $id; var $name; var $db; var $row; var $type; - function jrn ($p_cn,$p_id){ + var $nb; /*!< default number of rows by + default 10 */ + function Acc_Ledger ($p_cn,$p_id){ $this->id=$p_id; $this->db=$p_cn; $this->row=null; + $this->nb=10; } /*! * \brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL @@ -634,5 +646,410 @@ class jrn { $response=array($deb,$cred); return $response; } + /*! + * \brief Show a select list of the ledger you can access in + * writing, the security is taken in care but show the readable AND + * writable ledger + * \param + * \param + * \param + * + * + * \return object widget select + */ + function select_ledger() { + $user=new cl_user($this->db); + $array=$user->get_ledger(); + $idx=0; + $ret=array(); + + foreach ( $array as $value) { + $ret[$idx]['value']=$value['jrn_def_id']; + $ret[$idx]['label']=$value['jrn_def_name']; + $idx++; + } + + $select=new widget("select"); + $select->name='p_jrn'; + $select->value=$ret; + $select->selected=$this->id; + return $select; + } +/*! + * \brief retrieve the jrn_def_fiche and return them into a array + * index deb, cred + * \param + * \param + * \param + * + * + * \return return an array ('deb'=> ,'cred'=>) + */ + function get_fiche_def() { + $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ". + " from jrn_def where ". + " jrn_def_id = ".$this->id; + + $r=ExecSql($this->db,$sql); + + $res=pg_fetch_all($r); + if ( empty($res) ) return null; + print_r($res); + return $res[0]; + } +/*! + * \brief retrieve the jrn_def_class_deb and return it + * + * \param + * \param + * \param + * + * + * \return return an string + */ + function get_class_def() { + $sql="select jrn_def_class_cred ". + " from jrn_def where ". + " jrn_def_id = ".$this->id; + print_r($sql); + $r=ExecSql($this->db,$sql); + + $res=pg_fetch_all($r); + print_r($res); + if ( empty($res) ) return null; + return $res[0]; + } + +/*! + * \brief show the result of the array + * \param $p_array array from the form + * \param + * \param + * + * + * \return string + */ + function show_summary($p_array) { + $this->id=$p_array['p_jrn']; + if ( empty($p_array)) return 'Aucun résultat'; + extract($p_array); + $ret=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.='
Date : $date
Description $desc
'; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $own=new own($this->db); + $hidden=new widget('hidden'); + $ret.=$hidden->IOValue('date',$date); + $ret.=$hidden->IOValue('desc',$desc); + // For predefined operation + $ret.=$hidden->IOValue('e_comm',$desc); + $ret.=$hidden->IOValue('jrn_type',$this->get_type()); + $ret.=$hidden->IOValue('p_jrn',$this->id); + $ret.=$hidden->IOValue('nb_item',$this->nb); + $ret.=dossier::hidden(); + for ($i=0;$i<$this->nb;$i++) { + $ret.=""; + if ( trim(${'qc_'.$i})!="") { + $oqc=new fiche($this->db); + $oqc->GetByQCode(${'qc_'.$i},false); + $ret.="'; + } + + if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "") { + $oposte=new poste($this->db,${'poste'.$i}); + $ret.="'; + } + + if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) == "") + continue; + + $ret.=""; + $ret.=""; + // CA + + if ( $own->MY_ANALYTIC!='nu') // use of AA + { + // show form + $op=new Anc_Operation($this->db); + $null=($own->MY_ANALYTIC=='op')?1:0; + $ret.=''; + + } + + + + $ret.=""; + } + $ret.="
Quick Code ou "; + $ret.="Poste Montant Débit
".${'qc_'.$i}.' - '. + $oqc->strAttribut(ATTR_DEF_NAME).$hidden->IOValue('qc_'.$i,${'qc_'.$i}). + '".${"poste".$i}." - ". + $oposte->GetName().$hidden->IOValue('poste'.$i,${'poste'.$i}). + '".${"amount".$i}.$hidden->IOValue('amount'.$i,${'amount'.$i}).""; + $ret.=(isset(${"ck$i"}))?"D":"C"; + $ret.=(isset(${"ck$i"}))?$hidden->IOValue('ck'.$i,${'ck'.$i}):""; + $ret.="'; + $ret.=$op->display_form_plan(null,$null,1,$i,round(${'amount'.$i},2)); + $ret.='
"; + return $ret; + } + + /*! + * \brief Show the form to encode your operation + * \param $p_array if you correct or use a predef operation + * \param $p_readonly 1 for readonly 0 for writable + * \param + * + * + * \return a string containing the form + */ + function show_form($p_array=null,$p_readonly=0) + { + if ( $p_readonly == 1 ) + return $this->show_summary($p_array); + + if ( $p_array != null ) + extract($p_array); + + $ret=""; + // Load the javascript + $ret.=JS_SEARCH_CARD; + $ret.=JS_SEARCH_POSTE; + $ret.=JS_AJAX_FICHE; + // + $ret.=""; + $ret.= ''; + + $ret.= ''; + + $ret.= '
'; + $wDate=new widget('js_date','Date','date'); + $wDate->table=1; + $wDate->readonly=$p_readonly; + $wDate->value=(isset($date))?$date:''; + + $ret.=$wDate->IOValue(); + $ret.= '
'; + $wDescription=new widget('text',"Description",'desc'); + $wDescription->readonly=$p_readonly; + $wDescription->table=1; + $wDescription->value=(isset($desc))?$desc:''; + $ret.=$wDescription->IOValue(); + $ret.= '
'; + + // $nb_row=(isset($nb))?$nb:$this->GetDefLine(); + $nb_row=$this->nb; + $hidden=new widget('hidden','nb','nb'); + $hidden->value=$nb_row; + $ret.=$hidden->IOValue(); + $ret.=dossier::hidden(); + $ret.=$hidden->IOValue('p_jrn',$this->id); + $ret.=$hidden->IOValue('jrn_type',$this->get_type()); + $ret.=''; + $ret.=''. + ''. + ''. + ''. + ''. + ''; + + for ($i = 0 ;$i<$nb_row;$i++){ + // Quick Code + $quick_code=new widget('js_search'); + $quick_code->name='qc_'.$i; + $quick_code->value=(isset(${'qc_'.$i}))?${'qc_'.$i}:""; + $quick_code->readonly=$p_readonly; + $quick_code->extra2=$this->id; + $quick_code->extra='filter'; + $qc_span=new widget('span','','qc_'.$i.'_label'); + + // Account + $poste=new widget('js_search_poste'); + $poste->name='poste'.$i; + $poste->value=(isset(${'poste'.$i}))?${"poste".$i}:''; + $poste->readonly=$p_readonly; + $poste->extra=$this->id; + $poste->extra2=$this->get_class_def(); + echo "get_class_Def returns"; + print_r($poste->extra2); + $poste_span=new widget('span','','poste'.$i.'_label'); + + // Amount + $amount=new widget('text'); + $amount->name='amount'.$i; + $amount->value=(isset(${'amount'.$i}))?${"amount".$i}:''; + $amount->readonly=$p_readonly; + + // D/C + $deb=new widget('checkbox'); + $deb->name='ck'.$i; + $deb->value=(isset(${'ck'.$i}))?${"ck".$i}:''; + $deb->readonly=$p_readonly; + + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + // If readonly == 1 then show CA + } + $ret.='
QuickcodePoste MontantDébit
'.$quick_code->IOValue().''.$qc_span->IOValue().''.$poste->IOValue().''.$poste_span->IOValue().''.$amount->IOValue().''.$deb->IOValue().'
'; + return $ret; + } + /*! + * \brief save the operation into the jrnx,jrn, , + * CA and pre_def + * \param + * \param + * \param + * + * + * \return + */ + function save ($p_array) { + extract ($p_array); + + try { + StartSql($this->db) ; + + $seq=NextSequence($this->db,'s_grpt'); + $internal=SetInternalCode($this->db,$seq,$this->id); + + $group=NextSequence($this->db,"s_oa_group"); + $own=new own($this->db); + $tot_amount=0; + for ($i=0;$i<$this->nb;$i++) + { + if ( ! isset (${'qc_'.$i}) && ! isset(${'poste'.$i})) + continue; + $acc_op=new Acc_Operation($this->db); + $quick_code=""; + // First we save the jrnx + if ( isset(${'qc_'.$i})) { + $qc=new fiche($this->db); + $qc->GetByQCode(${'qc_'.$i},false); + $poste=$qc->strAttribut(ATTR_DEF_ACCOUNT); + $quick_code=${'qc_'.$i}; + } + else { + $poste=${'poste'.$i}; + } + $acc_op->date=$date; + $acc_op->desc=$desc; + $acc_op->amount=${'amount'.$i}; + $acc_op->grpt=$seq; + $acc_op->poste=$poste; + $acc_op->jrn=$this->id; + $acc_op->type=(isset (${'ck'.$i}))?'d':'c'; + $acc_op->qcode=$quick_code; + $j_id=$acc_op->insert_jrnx(); + $tot_amount+=round($acc_op->amount,2); + + if ( $own->MY_ANALYTIC != "nu" ) + { + // for each item, insert into operation_analytique */ + $op=new Anc_Operation($this->db); + $op->oa_group=$group; + $op->j_id=$j_id; + $op->oa_date=$date; + $op->oa_debit=($acc_op->type=='d' )?'t':'f'; + $op->oa_description=$desc; + $op->save_form_plan($p_array,$i); + } + } + $acc_end=new Acc_Operation($this->db); + $acc_end->date=$date; + $acc_end->desc=$desc; + $acc_end->grpt=$seq; + $acc_end->jrn=$this->id; + if ( $acc_end->insert_jrn() == false ) + throw new Exception('Balance incorrecte'); + + ExecSql($this->db,"update jrn set jr_internal='".$internal."' where ". + " jr_grpt_id = ".$seq); + + // Save now the predef op + //------------------------ + if ( isset($save_opd)) { + $opd=new Pre_Op_Advanced($this->db); + $opd->name=(trim($desc)=='')?$internal:$desc; + $opd->get_post(); + $opd->save(); + } + } catch (Exception $e) { + Rollback($this->db); + echo 'OPERATION ANNULEE '; + echo '
'; + echo __FILE__.__LINE__.$e->getMessage(); + exit(); + } + Commit($this->db); + } + + /*! + * \brief get all the data from request and build the object + * \param + * \param + * \param + * + * + * \return + */ + function get_request() + { + $this->id=$_REQUEST['p_jrn']; + + } + /*! + * \brief this function is intended to test this class + * \param + * \param + * \param + * + * + * \return + */ + static function test_me() + { + html_page_start(); + $cn=DbConnect(dossier::id()); + $_SESSION['g_user']='phpcompta'; + $_SESSION['g_pass']='phpcompta'; + $id=(isset ($_POST['p_jrn']))?$_POST['p_jrn']:-1; + $a=new Acc_Ledger($cn,$id); + echo '
'; + echo $a->select_ledger()->IOValue(); + echo widget::submit_button('go','Test it'); + echo '
'; + if ( isset($_POST['go'])) { + echo "Ok "; + echo '
'; + echo $a->show_form(); + echo widget::submit_button('post_id','Try me'); + echo '
'; + } + if ( isset($_POST['post_id' ])) { + echo '
'; + echo $a->show_form($_POST,1); + echo widget::submit_button('save_it',"Sauver"); + echo '
'; + } + if ( isset($_POST['save_it' ])) { + $array=$_POST; + $array['save_opd']=1; + $a->save($array); + } + + } } diff --git a/include/class_acc_operation.php b/include/class_acc_operation.php new file mode 100644 index 000000000..4479bfff9 --- /dev/null +++ b/include/class_acc_operation.php @@ -0,0 +1,118 @@ +db=$p_cn; + $this->qcode=""; + $this->user=$_SESSION['g_user']; + $user=new cl_user($this->db); + $this->periode=$user->GetPeriode(); + } + /* ************************************************** + *\brief Insert into the table Jrn + * + * + * \return nothing + * + */ + + function insert_jrnx() + { + if ( $this->poste == "") return true; + + $debit=($this->type=='c')?'false':'true'; + + $sql=sprintf("select insert_jrnx + ('%s',abs(%.2f),%d,%d,%d,%s,'%s',%d,upper('%s'))", + $this->date,round($this->amount,2), + $this->poste,$this->grpt,$this->jrn, + $debit,$this->user,$this->periode,$this->qcode); + + $Res=ExecSql($this->db,$sql); + if ( $Res==false) return $Res; + $this->jrnx_id=GetSequence($this->db,'s_jrn_op'); + return $this->jrnx_id; + +} +/*! + ************************************************** + *\brief Insert into the table Jrn, the amount is computed from jrnx thanks the + * group id ($p_grpt) + * + * \return nothing + * + */ + + function insert_jrn() +{ + $p_comment=FormatString($this->desc); + + + // retrieve the value from jrnx + // + $montant_deb=getDBValue($this->db,"select sum(j_montant) from jrnx where j_debit='t' and j_grpt=".$this->grpt); + $montant_cred=getDBValue($this->db,"select sum(j_montant) from jrnx where j_debit='f' and j_grpt=".$this->grpt); + echo_debug('InsertJrn',__LINE__,"debit = $montant_deb credit = $montant_cred "); + + $amount=-1.0000; + if ( $montant_deb == $montant_cred ) { + $amount=$montant_deb; + } else { + echo "Erreur : balance incorrecte : débit = $montant_deb crédit = $montant_cred"; + return false; + } + // if amount == -1then the triggers will throw an error + // + $sql=sprintf("insert into jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_ech,jr_grpt_id,jr_tech_per) + values ( %d,abs(%.2f),'%s',to_date('%s','DD.MM.YYYY'),null,%d,%d)", + $this->jrn, $amount,$p_comment,$this->date,$this->grpt,$this->periode); + + + $Res=ExecSql($this->db,$sql); + if ( $Res == false) return false; + return GetSequence($this->db,'s_jrn'); +} + +} diff --git a/include/class_list_ca.php b/include/class_list_ca.php index de4edf338..f3b155840 100644 --- a/include/class_list_ca.php +++ b/include/class_list_ca.php @@ -28,7 +28,7 @@ */ require_once ('class_plananalytic.php'); require_once ('class_print_ca.php'); -require_once ('class_operation.php'); +require_once ('class_anc_operation.php'); /*! * \brief manage the CA listing * @@ -97,7 +97,7 @@ class list_ca extends print_ca { */ function get_data() { - $op=new operation ($this->db); + $op=new Anc_Operation ($this->db); $op->pa_id=$this->pa_id; $array=$op->get_list($this->from,$this->to,$this->from_poste,$this->to_poste); return $array; diff --git a/include/class_pre_op_advanced.php b/include/class_pre_op_advanced.php new file mode 100644 index 000000000..ffdd5dab4 --- /dev/null +++ b/include/class_pre_op_advanced.php @@ -0,0 +1,109 @@ +operation->p_jrn+=5000; + extract($_POST); + for ($i=0;$i<$this->operation->nb_item;$i++) { + $this->{'poste'.$i}=(isset($_POST['qc_'.$i]))?$_POST['qc_'.$i]:$_POST['poste'.$i]; + $this->{"amount".$i}=$_POST['amount'.$i]; + $this->{"ck".$i}=($_POST['ck'.$i]=='c')?'t':'f'; + + } + } +/*! + * \brief save the detail and op in the database + * + */ + function save() { + try { + StartSql($this->db); + if ($this->operation->save() == false ) + return; + // save the selling + for ($i=0;$i<$this->operation->nb_item;$i++) { + $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'. + 'opd_debit,od_id)'. + ' values '. + "('%s',%.2f,%d,%f,'%s',%d)", + $this->{"poste".$i}, + $this->{"amount".$i}, + $this->{"ck".$i}, + $this->operation->od_id + ); + ExecSql($this->db,$sql); + } + } catch (Exception $e) { + echo ($e->getMessage()); + Rollback($this->db); + } + + } + /*!\brief compute an array accordingly with the FormVenView function + */ + function compute_array() { + $count=0; + $a_op=$this->operation->load(); + $array=$this->operation->compute_array($a_op); + $p_array=$this->load(); + foreach ($p_array as $row) { + if ( $row['opd_debit']=='t') { + $array+=array('e_client'=>$row['opd_poste']); + } else { + $array+=array("e_march".$count=>$row['opd_poste'], + "e_march".$count."_sell"=>$row['opd_amount'], + "e_march".$count."_tva_id"=>$row['opd_tva_id'], + "e_quant".$count=>$row['opd_quantity'] + ); + $count++; + } + } + return $array; + } + /*!\brief load the data from the database and return an array + * \return an array + */ + function load() { + $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,". + " opd_quantity from op_predef_detail where od_id=".$this->operation->od_id. + " order by opd_id"; + $res=ExecSql($this->db,$sql); + $array=pg_fetch_all($res); + return $array; + } + function set_od_id($p_id) { + $this->operation->od_id=$p_id; + } +} diff --git a/include/class_user.php b/include/class_user.php index d850b5cc2..b396f741c 100644 --- a/include/class_user.php +++ b/include/class_user.php @@ -135,8 +135,35 @@ class cl_user { return $ret; } - - function getJrn() { +/*! + * \brief get all the available ledgers for the current user + * \param none + * \param + * \param + * + * + * \return an array + */ + function get_ledger() { + if ( $this->admin != 1) { + $sql="select jrn_def_id,jrn_def_type, +jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv, + jrn_deb_max_line,jrn_cred_max_line + from jrn_def join jrn_type on jrn_def_type=jrn_type_id + join user_sec_jrn on uj_jrn_id=jrn_def_id + where + uj_login='".$this->id."' + and uj_priv !='X' + order by jrn_Def_id"; + }else { + $sql="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 + order by jrn_Def_id"; + } + $res=ExecSql($this->db,$sql); + $array=pg_fetch_all($res); + return $array; } /*! ************************************************** diff --git a/include/constant.php b/include/constant.php index a2971a52b..62303ee4f 100644 --- a/include/constant.php +++ b/include/constant.php @@ -33,7 +33,7 @@ define ("domaine","rel3"); define ("MAX_COMPTE",4); -define ("DEBUG","false"); +define ("DEBUG","true"); // securite correspond a la table // action @@ -170,6 +170,10 @@ define ("JS_SEARCH_CARD"," define ("JS_CONCERNED_OP",' '); +define ('JS_CALENDAR',' +'); + // One line calculator define ("JS_CALC_LINE",'
diff --git a/include/depense.inc.php b/include/depense.inc.php index cd5f78145..057a61081 100644 --- a/include/depense.inc.php +++ b/include/depense.inc.php @@ -18,7 +18,7 @@ */ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr -require_once('class_jrn.php'); +require_once('class_acc_ledger.php'); require_once('user_form_ach.php'); require_once('jrn.php'); require_once("class_document.php"); @@ -313,7 +313,7 @@ if ( $p_jrn != -1 ) exit -1; } - $jrn=new jrn($cn, $p_jrn); + $jrn=new Acc_Ledger($cn, $p_jrn); echo_debug('depense.inc.php',__LINE__,"Blank form"); // Submit button in the form $submit=' diff --git a/include/facture.inc.php b/include/facture.inc.php index ffd75b236..8aeb39878 100644 --- a/include/facture.inc.php +++ b/include/facture.inc.php @@ -18,7 +18,7 @@ */ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr -require_once('class_jrn.php'); +require_once('class_acc_ledger.php'); require_once('user_form_ven.php'); require_once('jrn.php'); require_once("class_document.php"); @@ -302,7 +302,7 @@ if ( $p_jrn != -1 ) exit -1; } - $jrn=new jrn($cn, $p_jrn); + $jrn=new Acc_Ledger($cn, $p_jrn); echo_debug('facture.inc.php.php',__LINE__,"Blank form"); // Show an empty form of invoice $form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),null,false,$jrn->GetDefLine()); diff --git a/include/impress_inc.php b/include/impress_inc.php index 79e9b7beb..932485e50 100644 --- a/include/impress_inc.php +++ b/include/impress_inc.php @@ -404,7 +404,7 @@ function GetRappelSimple ($p_cn,$p_jrn_id,$p_jrn_type,$p_from,&$arap) "p_end < (select p_end from parm_periode where p_id=$p_from) ". " and p_start <= (select p_start from parm_periode where p_id=$p_from)"); - $j=new jrn($p_cn,$p_jrn_id); + $j=new Acc_Ledger($p_cn,$p_jrn_id); $a=$j->GetRowSimple($previous,$previous,$cent='on'); $total_tvac=0.0; $total_htva=0.0; diff --git a/include/impress_jrn.php b/include/impress_jrn.php index 867adf86b..111b934dd 100644 --- a/include/impress_jrn.php +++ b/include/impress_jrn.php @@ -32,12 +32,12 @@ $gDossier=dossier::id(); // after in pdf or cvs //----------------------------------------------------- if ( isset( $_POST['bt_html'] ) ) { -include("class_jrn.php"); +include("class_acc_ledger.php"); $p_cent=( isset ( $_POST['cent']) )?'on':'off'; // $POST=from_periode, to_periode, jrn_id, cent $d=var_export($_POST,true); echo_debug('impress_jrn.php',__LINE__,$d); - $Jrn=new jrn($cn,$_POST['jrn_id']); + $Jrn=new Acc_Ledger($cn,$_POST['jrn_id']); $Jrn->GetName(); if ( $_POST['p_simple']==0 ) { diff --git a/include/jrn.php b/include/jrn.php index 43ca0d9ee..21a687488 100644 --- a/include/jrn.php +++ b/include/jrn.php @@ -27,7 +27,7 @@ require_once('class_fiche.php'); require_once ('class_gestion_sold.php'); require_once ('class_gestion_purchase.php'); require_once ('class_plananalytic.php'); -require_once ('class_operation.php'); +require_once ('class_anc_operation.php'); /*! * \brief Display the form to UPDATE account operation in the expert view * @@ -1107,7 +1107,7 @@ function GetDataJrnJrIdUser ($p_cn,$p_jr_id) { function display_table_ca($p_cn,$p_seq,$p_jid,$p_own,$p_mode,$p_amount) { echo_debug(__FILE__.':'.__LINE__,'parameter $p_cn,$p_seq,$p_jid,$p_own,$p_mode',"$p_cn,$p_seq,$p_jid,p_own,$p_mode"); - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $array=$op->get_by_jid($p_jid) ; echo_debug(__FILE__.':'.__LINE__,"display_table_ca \$p_jid",$p_jid); echo_debug(__FILE__.':'.__LINE__,"display_table_ca \$array",$array); diff --git a/include/user_action_ach.php b/include/user_action_ach.php index 887e4cbf9..dd35727f9 100644 --- a/include/user_action_ach.php +++ b/include/user_action_ach.php @@ -26,7 +26,7 @@ require_once("user_form_ach.php"); require_once ("preference.php"); require_once ("user_common.php"); require_once("class_widget.php"); -require_once("class_jrn.php"); +require_once("class_acc_ledger.php"); require_once ('class_own.php'); $own=new own($cn); @@ -71,7 +71,7 @@ if ( $action == 'new' ) { // Submit button in the form $submit=' '; - $jrn=new jrn($cn, $_GET['p_jrn']); + $jrn=new Acc_Ledger($cn, $_GET['p_jrn']); $r=FormAchInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,$submit,false,$jrn->getDefLine()); //-------------------- // predef op. diff --git a/include/user_action_fin.php b/include/user_action_fin.php index fc31282c2..a3746eaf2 100644 --- a/include/user_action_fin.php +++ b/include/user_action_fin.php @@ -27,7 +27,7 @@ echo_debug('user_action_fin.php',__LINE__,"include user_action_fin.php"); require_once("user_form_fin.php"); include_once("class_widget.php"); require_once("class_parm_code.php"); -require_once("class_jrn.php"); +require_once("class_acc_ledger.php"); require_once ('class_pre_op_fin.php'); $cn=DbConnect($gDossier); @@ -75,7 +75,7 @@ if ( $action == 'new' ) { '; // add a one-line calculator $p_jrn=$_GET['p_jrn']; - $jrn=new jrn($cn, $p_jrn); + $jrn=new Acc_Ledger($cn, $p_jrn); $r=FormFin($cn,$p_jrn,$User->GetPeriode(),$submit,null,false,$jrn->GetDefLine()); echo '
'; diff --git a/include/user_action_ven.php b/include/user_action_ven.php index fa1aabf43..29fa1a83f 100644 --- a/include/user_action_ven.php +++ b/include/user_action_ven.php @@ -26,7 +26,7 @@ echo_debug('user_action_ven.php',__LINE__,"include user_action_ven.php"); require_once("user_form_ven.php"); include_once("class_widget.php"); -require_once("class_jrn.php"); +require_once("class_acc_ledger.php"); require_once('class_dossier.php'); $gDossier=dossier::id(); if ( CheckJrn($gDossier,$_SESSION['g_user'],$_GET['p_jrn']) != 2 ) { @@ -92,7 +92,7 @@ if ( $action == 'insert_vente' ) { // We want a blank form if ( $blank==1) { - $jrn=new jrn($cn, $_GET['p_jrn']); + $jrn=new Acc_Ledger($cn, $_GET['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()); diff --git a/include/user_form_ach.php b/include/user_form_ach.php index 7448061e8..4c36b6970 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -30,7 +30,7 @@ require_once("user_common.php"); require_once("class_parm_code.php"); require_once ('class_plananalytic.php'); require_once ('class_own.php'); -require_once ('class_operation.php'); +require_once ('class_anc_operation.php'); require_once ('class_pre_op_ach.php'); /*! @@ -671,7 +671,7 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi if ( $own->MY_ANALYTIC!='nu') // use of AA { // show form - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $null=($own->MY_ANALYTIC=='op')?1:0; $p_mode=($p_piece)?1:0; $r.=''; @@ -907,7 +907,7 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) if ( $own->MY_ANALYTIC != "nu" ) { // for each item, insert into operation_analytique */ - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $op->oa_group=$group; $op->j_id=$j_id; $op->oa_date=$e_date; diff --git a/include/user_form_ods.php b/include/user_form_ods.php index 339d4ddf4..497d6de34 100644 --- a/include/user_form_ods.php +++ b/include/user_form_ods.php @@ -27,7 +27,7 @@ require_once("fiche_inc.php"); require_once("user_common.php"); require_once ('class_plananalytic.php'); require_once ('class_own.php'); -require_once ('class_operation.php'); +require_once ('class_anc_operation.php'); require_once ('class_pre_op_ods.php'); /*! \file * \brief Functions for the ledger of misc. operation @@ -207,7 +207,7 @@ $r.="
MY_ANALYTIC!='nu') // use of AA { // show form - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $null=($own->MY_ANALYTIC=='op')?1:0; $r.=''; $p_mode=($p_saved)?0:1; @@ -384,7 +384,7 @@ function RecordODS($p_cn,$p_array,$p_user,$p_jrn) if ( $own->MY_ANALYTIC != "nu" ) { // for each item, insert into operation_analytique */ - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $op->oa_group=$group; $op->j_id=$j_id; $op->oa_date=$e_date; diff --git a/include/user_form_ven.php b/include/user_form_ven.php index 6b588c99e..6e30c5684 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -28,7 +28,7 @@ require_once("fiche_inc.php"); require_once("user_common.php"); require_once ("class_own.php"); require_once ("class_plananalytic.php"); -require_once ('class_operation.php'); +require_once ('class_anc_operation.php'); require_once ('class_pre_op_ven.php'); require_once ('class_own.php'); @@ -574,7 +574,7 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' if ( $own->MY_ANALYTIC!='nu') // use of AA { // show form - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $null=($own->MY_ANALYTIC=='op')?1:0; $r.=''; $p_mode=($p_doc=="form")?1:0; @@ -767,7 +767,7 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) if ( $own->MY_ANALYTIC != "nu" ) { // for each item, insert into operation_analytique */ - $op=new operation($p_cn); + $op=new Anc_Operation($p_cn); $op->oa_group=$group; $op->j_id=$j_id; $op->oa_date=$e_date; diff --git a/include/user_menu.php b/include/user_menu.php index 8efe0ed76..a2a0e3ab8 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -174,6 +174,8 @@ function ShowMenuCompta($p_high="") array("user_jrn.php?jrn_type=ACH&".$str_dossier,"Dépense"), array("user_jrn.php?jrn_type=FIN&".$str_dossier,"Financier"), array("user_jrn.php?jrn_type=ODS&".$str_dossier,"Op. Diverses"), + array('compta.php?p_action=quick_writing&'.$str_dossier,'Ecriture rapide'), + array("compta.php?p_action=impress&".$str_dossier,"Impression","Impression",5), array("compta.php?p_action=fiche&".$str_dossier,"Fiche","Ajouter, modifier ou effacer des fiches",6), array("user_advanced.php?".$str_dossier,"Avancé","Opérations délicates"),