diff --git a/contrib/document_test/facture-calc.ods b/contrib/document_test/facture-calc.ods index 5c450090f..97a96b0eb 100644 Binary files a/contrib/document_test/facture-calc.ods and b/contrib/document_test/facture-calc.ods differ diff --git a/contrib/document_test/facture.odt b/contrib/document_test/facture.odt index 460a0f33d..fc80858bf 100644 Binary files a/contrib/document_test/facture.odt and b/contrib/document_test/facture.odt differ diff --git a/contrib/document_test/note-de-frais.odt b/contrib/document_test/note-de-frais.odt new file mode 100644 index 000000000..4f6993459 Binary files /dev/null and b/contrib/document_test/note-de-frais.odt differ diff --git a/doc/manuel-fr.odt b/doc/manuel-fr.odt index 65391f05e..a126baa1a 100644 Binary files a/doc/manuel-fr.odt and b/doc/manuel-fr.odt differ diff --git a/html/admin/sql/patch/upgrade52.sql b/html/admin/sql/patch/upgrade52.sql new file mode 100644 index 000000000..61332e374 --- /dev/null +++ b/html/admin/sql/patch/upgrade52.sql @@ -0,0 +1,37 @@ +begin; +CREATE TABLE mod_payment ( + mp_id serial, + mp_lib text NOT NULL, + mp_jrn_def_id integer NOT NULL, + mp_type character varying(3) NOT NULL, + mp_fd_id bigint , + mp_qcode text +); +COMMENT ON TABLE mod_payment IS 'Contains the different media of payment and the corresponding ledger'; + +INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (2, 'Caisse', 1, 'VEN', NULL, NULL); +INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (4, 'Caisse', 1, 'ACH', NULL, NULL); +INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (1, 'Paiement électronique', 1, 'VEN', NULL, NULL); +INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (3, 'Par gérant ou administrateur', 2, 'ACH', NULL, NULL); + +ALTER TABLE ONLY mod_payment + ADD CONSTRAINT mod_payment_pkey PRIMARY KEY (mp_id); +ALTER TABLE ONLY mod_payment + ADD CONSTRAINT mod_payment_mp_fd_id_fkey FOREIGN KEY (mp_fd_id) REFERENCES fiche_def(fd_id); +ALTER TABLE ONLY mod_payment + ADD CONSTRAINT mod_payment_mp_jrn_def_id_fkey FOREIGN KEY (mp_jrn_def_id) REFERENCES jrn_def(jrn_def_id); +INSERT INTO document_type (dt_id, dt_value) VALUES (10, 'Note de frais'); + +insert into fiche_def_ref (frd_id,frd_text) values (25,'Compte Salarié / Administrateur'); +insert into attr_min values (25,1); +insert into attr_min values(25,4); +insert into attr_min values (25,3); +insert into attr_min values(25,5); +insert into attr_min values (25,15); +insert into attr_min values(25,16); +insert into attr_min values(25,24); +insert into attr_min values(25,23); + + +update version set val=53; +commit; diff --git a/html/fiche_search.php b/html/fiche_search.php index 0981fafd0..03f909a59 100644 --- a/html/fiche_search.php +++ b/html/fiche_search.php @@ -157,11 +157,16 @@ if ( $sql="select * from vw_fiche_attr where fd_id in ( $list_fiche )"; + } elseif( strpos($e_type,'frd_id')===0 ) { + /* $e_type must be something like frd_id in (...) */ + $sql="select * from vw_fiche_attr where $e_type "; + } // 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 fd_id in ( $list_fiche )"; + echo $sql; } // e_fic_search contains the pattern diff --git a/html/parametre.php b/html/parametre.php index 91d7cb9fe..8d0ef1a5c 100644 --- a/html/parametre.php +++ b/html/parametre.php @@ -24,7 +24,6 @@ */ include_once ("ac_common.php"); -html_page_start($_SESSION['g_theme']); include_once ("postgres.php"); require_once("class_widget.php"); require_once('class_dossier.php'); @@ -37,6 +36,7 @@ include_once ("class_user.php"); $User=new User($rep); $User->Check(); +html_page_start($_SESSION['g_theme']); include_once("preference.php"); include_once("user_menu.php"); echo '
'; @@ -65,7 +65,7 @@ switch ($p_action) { case 'company': $default=1; break; - case 'devise': + case 'divers': $default=2; break; case 'tva': @@ -129,54 +129,86 @@ if ( $p_action == "fiche" ) require_once('fiche_def.inc.php'); return; } -echo '
'; -//----------------------------------------------------- -// Currency -//----------------------------------------------------- -if ( $p_action == "change" ) { - $p_mid=$_GET['p_mid']; - $p_rate=$_GET['p_rate']; - $p_code=$_GET['p_code']; - echo '
'; - echo dossier::hidden(); - echo ''; - echo ' '; - echo ' '; - echo ' '; - echo '
'; +if ( $p_action == 'divers') { + $s=dossier::get().'&PHPSESSID='.$_REQUEST['PHPSESSID']; + + $array = array (/*array('parametre.php?p_action=divers&sa=devise&'.$s, + 'Devise','Devise',1),*/ + array('parametre.php?p_action=divers&sa=mp&'.$s, + 'Moyen de paiement','Moyen de paiement',2) + ); + $sa=(isset($_REQUEST['sa']))?$_REQUEST['sa']:''; + $sb=(isset($_REQUEST['sb']))?$_REQUEST['sb']:''; + $def=0; + switch ($sa) { + case 'devise': + $def=1; + break; + case 'mp': + $def=2; + break; + } + echo ''; + + if ( $sa=='devise') { + echo '
'; + //----------------------------------------------------- + // Currency + //----------------------------------------------------- + if ( $sb == "c" ) { + $p_mid=$_GET['p_mid']; + $p_rate=$_GET['p_rate']; + $p_code=$_GET['p_code']; + + echo '
'; + echo dossier::hidden(); + echo ''; + echo ' '; + echo ' '; + echo ' '; + echo '
'; + } + if ( $sb == "ch") { + $p_devise=$_GET['p_code']; + $p_id=$_GET['p_id']; + $p_rate=$_GET['p_rate']; + $Res=ExecSql($cn,"update parm_money set pm_code='$p_devise',pm_rate=$p_rate where pm_id=$p_id"); + ShowDevise($cn); + + } + if ( $sb == "a") { + $p_devise=$_POST['p_devise']; + $p_rate=$_POST['p_rate']; + $Res=ExecSql($cn,"insert into parm_money ( pm_code,pm_rate) values ('$p_devise',$p_rate) "); + ShowDevise($cn); + + } + + if ( $sb == "d") { + $p_id=$_GET['p_mid']; + $Res=ExecSql($cn,"delete from parm_money where pm_id=$p_id"); + ShowDevise($cn); + } + + + if ( $p_action=="divers") { + ShowDevise($cn); + } + } + if ( $sa=='mp') { + + require_once('payment_middle.inc.php'); + exit; + } } -if ( $action == "Change") { - $p_devise=$_POST['p_devise']; - $p_id=$_POST['p_id']; - $p_rate=$_POST['p_rate']; - $Res=ExecSql($cn,"update parm_money set pm_code='$p_devise',pm_rate=$p_rate where pm_id=$p_id"); - ShowDevise($cn); - -} -if ( $action == "Ajout") { - $p_devise=$_POST['p_devise']; - $p_rate=$_POST['p_rate']; - $Res=ExecSql($cn,"insert into parm_money ( pm_code,pm_rate) values ('$p_devise',$p_rate) "); - ShowDevise($cn); - -} - -if ( $p_action == "delete") { - $p_id=$_GET['p_mid']; - $Res=ExecSql($cn,"delete from parm_money where pm_id=$p_id"); - ShowDevise($cn); -} - - -if ( $p_action=="devise") { - ShowDevise($cn); -} - //----------------------------------------------------- // Coord societe //----------------------------------------------------- if ( $p_action=='company') { + echo '
'; require_once("class_own.php"); require_once("class_widget.php"); if ( isset ($_POST['record_company'] )) { @@ -238,6 +270,8 @@ if ( $p_action=='company') { $submit=new widget("submit"); echo widget::submit("record_company","Enregistre"); echo ""; + echo '
'; + exit(); } //----------------------------------------------------- // Document diff --git a/html/test.php b/html/test.php index a064badb7..46197a5aa 100644 --- a/html/test.php +++ b/html/test.php @@ -121,7 +121,7 @@ Acc_Ledger_Info::test_me(); require('class_acc_compute.php'); Acc_Compute::test_me(); -*/ + require_once('class_todo_list.php'); require_once('class_widget.php'); @@ -138,3 +138,6 @@ echo 'date :
'; echo ''; echo ''; +*/ +require_once('class_acc_payment.php'); +Acc_Payment::test_me(); \ No newline at end of file diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 68541d980..65a82c231 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -1545,4 +1545,56 @@ function get_last_date() $date=getDbValue($this->db,$sql,array($this->id)); return $date; } + /*!\brief retrieve the jr_id thanks the internal code, do not change + *anything to the current object + *\param the internal code + *\return the jr_id or 0 if not found + */ + function get_id($p_internal) { + $sql='select jr_id from jrn where jr_internal=$1'; + $value=getDbValue($this->db,$sql,array($p_internal)); + if ($value=='') $value=0; + return $value; + } + /*!\brief create the invoice and saved it as attachment to the + *operation, + *\param $internal is the internal code + *\param $p_array is normally the $_POST + *\return a string + */ + function create_document($internal,$p_array) { + extract ($p_array); + $doc=new Document($this->db); + $doc->f_id=$e_client; + $doc->md_id=$gen_doc; + $doc->ag_id=0; + $str_file=$doc->Generate(); + // Move the document to the jrn + $doc->MoveDocumentPj($internal); + // Update the comment with invoice number + $sql="update jrn set jr_comment=' document ".$doc->d_number."' where jr_internal='$internal'"; + ExecSql($this->db,$sql); + return '

'.$str_file.'

'; + + } + /*!\brief check if the payment method is valid + *\param $e_mp is the value and $e_mp_qcode is the quickcode + *\return nothing throw an Exception + */ + public function check_payment($e_mp,$e_mp_qcode) { + /* Check if the "paid by" is empty, */ + if ( $e_mp != 0) { + /* the paid by is not empty then check if valid */ + $empl=new fiche($this->db); + $empl->get_by_qcode($e_mp_qcode); + if ( $empl->empty_attribute(ATTR_DEF_ACCOUNT)== true) { + throw new AcException('Celui qui paie n\' a pas de poste comptable',20); + } + $poste=new Acc_Account_Ledger($this->db,$empl->strAttribut(ATTR_DEF_ACCOUNT)); + if ( $poste->load() == false ){ + throw new AcException('Pour la fiche'.$empl->quick_code.' le poste comptable ['.$poste->id.'n\'existe pas',9); + + } + } + } } diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index a323c2a87..f1b6e2cc2 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -28,6 +28,7 @@ require_once('class_acc_compute.php'); require_once('class_anc_operation.php'); require_once('user_common.php'); require_once('class_acc_parm_code.php'); +require_once('class_acc_payment.php'); /*!\brief Handle the ledger of purchase, * * @@ -97,14 +98,19 @@ class Acc_Ledger_Purchase extends Acc_Ledger { throw new AcException('La fiche '.$e_client.'n\'est pas accessible à ce journal',10); $nb=0; + //------------------------------------------------------ + // The "Paid By" check + //------------------------------------------------------ + if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp}); + //---------------------------------------- // foreach item //---------------------------------------- for ($i=0;$i< $nb_item;$i++) { if ( strlen(trim(${'e_march'.$i}))== 0) continue; /* check if amount are numeric and */ - if ( isNumber(${'e_march'.$i.'_buy'}) == 0 ) + if ( isNumber(${'e_march'.$i.'_price'}) == 0 ) throw new AcException('La fiche '.${'e_march'.$i}.'a un montant invalide ['.${'e_march'.$i}.']',6); if ( isNumber(${'e_quant'.$i}) == 0 ) throw new AcException('La fiche '.${'e_march'.$i}.'a une quantité invalide ['.${'e_quant'.$i}.']',7); @@ -165,7 +171,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { /* Save all the items without vat and no deductible vat and expense*/ for ($i=0;$i< $nb_item;$i++) { if ( strlen(trim(${'e_march'.$i})) == 0 ) continue; - if ( ${'e_march'.$i.'_buy'} == 0 ) continue; + if ( ${'e_march'.$i.'_price'} == 0 ) continue; if ( ${'e_quant'.$i} == 0 ) continue; /* First we save all the items without vat */ @@ -179,7 +185,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $oTva->load(); /* We have to compute all the amount thanks Acc_Compute */ - $amount=bcmul(${'e_march'.$i.'_buy'},${'e_quant'.$i}); + $amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i}); $acc_amount=new Acc_Compute(); $acc_amount->check=false; $acc_amount->set_parameter('amount',$amount); @@ -401,6 +407,74 @@ class Acc_Ledger_Purchase extends Acc_Ledger { if ( sizeof($_FILES) != 0 ) save_upload_document($this->db,$seq); } + /* Generate an document and save it into the database */ + if ( isset($_POST['gen_invoice']) && $e_mp != 0) { + $p_array['e_client']=${'e_mp_qcode_'.$e_mp}; + echo $this->create_document($internal,$p_array); + echo '
'; + } + + //---------------------------------------- + // Save the payer + //---------------------------------------- + if ( $e_mp != 0 ) { + /* mp */ + $mp=new Acc_Payment($this->db,$e_mp); + $mp->load(); + + /* fiche */ + if ($mp->get_parameter('qcode') == '') + $fqcode=${'e_mp_qcode_'.$e_mp}; + else + $fqcode=$mp->get_parameter('qcode'); + + $acfiche = new fiche($this->db); + $acfiche->get_by_qcode($fqcode); + + /* jrnx */ + $acseq=NextSequence($this->db,'s_grpt'); + $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger')); + $acinternal=$acjrn->compute_internal_code($acseq); + + /* Insert paid by */ + $acc_pay=new Acc_Operation($this->db); + $acc_pay->date=$e_date; + $acc_pay->poste=$acfiche->strAttribut(ATTR_DEF_ACCOUNT); + $acc_pay->qcode=$fqcode; + $acc_pay->amount=abs(round($tot_debit,2)); + $acc_pay->desc=$e_comm; + $acc_pay->grpt=$acseq; + $acc_pay->jrn=$mp->get_parameter('ledger'); + $acc_pay->periode=$periode; + $acc_pay->type='c'; + $acc_pay->insert_jrnx(); + + /* Insert supplier */ + $acc_pay=new Acc_Operation($this->db); + $acc_pay->date=$e_date; + $acc_pay->poste=$poste; + $acc_pay->qcode=$e_client; + $acc_pay->amount=abs(round($tot_debit,2)); + $acc_pay->desc=$e_comm; + $acc_pay->grpt=$acseq; + $acc_pay->jrn=$mp->get_parameter('ledger'); + $acc_pay->periode=$periode; + $acc_pay->type='d'; + $acc_pay->insert_jrnx(); + + /* insert into jrn */ + $acc_pay->insert_jrn(); + $acjrn->grpt_id=$acseq; + $acjrn->update_internal_code($acinternal); + + $r1=$this->get_id($internal); + $r2=$this->get_id($acinternal); + + /* Reconcialiation */ + $rec=new Acc_Reconciliation($this->db); + $rec->set_jr_id($r1); + $rec->insert($r2); + } }//end try catch (Exception $e) { @@ -657,7 +731,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { // Code id, price & vat code //-- $march=(isset(${"e_march$i"}))?${"e_march$i"}:""; - $march_buy=(isset(${"e_march".$i."_buy"}))?${"e_march".$i."_buy"}:""; + $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""; $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:""; $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:""; @@ -706,7 +780,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $Price->table=1; $Price->size=9; $Price->javascript="onBlur='clean_tva($i);compute_purchase($i)'"; - $r.=$Price->IOValue("e_march".$i."_buy",$march_buy); + $r.=$Price->IOValue("e_march".$i."_price",$march_price); // vat label //-- $select_tva=make_array($this->db,"select tva_id,tva_label from tva_rate order by tva_rate desc",0); @@ -757,12 +831,23 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $r.='
Total TVA'; $r.='
Total TVAC'; $r.="
"; + $r.=widget::button('add_item','Ajout article', ' onClick="ledger_sold_add_row()"'); $r.=""; + //---------------------------------------------------------------------- + /* Paid By */ + $r.='
'; + $r.=' Payé par '; + $mp=new Acc_Payment($this->db); + $mp->set_parameter('type','ACH'); + $r.=$mp->select(); + $r.='
'; + + + // Set correctly the REQUEST param for jrn_type $r.=widget::hidden('jrn_type','ACH'); - $r.=widget::button('add_item','Ajout article', ' onClick="ledger_sold_add_row()"'); $r.=widget::submit("view_invoice","Enregistrer"); $r.=widget::reset('Effacer '); $r.=''; @@ -839,7 +924,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $oTva=new Acc_Tva($this->db); $oTva->set_parameter('id',$idx_tva); $oTva->load(); - $amount=bcmul(${"e_march".$i."_buy"},${'e_quant'.$i}); + $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i}); //----- if tva_amount is not given we compute the vat ---- if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0) { @@ -866,7 +951,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $r.=$fiche_name; $r.=''; $r.=''; - $r.=${"e_march".$i."_buy"}; + $r.=${"e_march".$i."_price"}; $r.=''; $r.=''; $r.=${"e_quant".$i}; @@ -944,18 +1029,45 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $r.=widget::hidden('e_date',$e_date); $r.=widget::hidden('e_ech',$e_ech); $r.=widget::hidden('jrn_type',$jrn_type); + $e_mp=(isset($e_mp))?$e_mp:0; + $r.=widget::hidden('e_mp',$e_mp); + /* Paid by */ + /* if the paymethod is not 0 and if a quick code is given */ + if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 ) { + $r.=widget::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp}); + + /* needed for generating a invoice */ + $r.=widget::hidden('qcode_dest',${'e_mp_qcode_'.$e_mp}); + + $r.="Payé par ".${'e_mp_qcode_'.$e_mp}; + $r.='
'; + } for ($i=0;$i < $nb_item;$i++) { $r.=widget::hidden("e_march".$i,${"e_march".$i}); - $r.=widget::hidden("e_march".$i."_buy",${"e_march".$i."_buy"}); + $r.=widget::hidden("e_march".$i."_price",${"e_march".$i."_price"}); $r.=widget::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"}); $r.=widget::hidden('e_march'.$i.'_tva_amount', ${'e_march'.$i.'_tva_amount'}); $r.=widget::hidden("e_quant".$i,${"e_quant".$i}); } - // check for upload piece + // check for upload piece $file=new widget("file"); $file->table=0; $r.="Ajoutez une pièce justificative "; $r.=$file->IOValue("pj",""); + /* Propose to generate a note of fee */ + if ( CountSql($this->db, + "select md_id,md_name from document_modele where md_type=10") > 0 ) + { + + + $r.='ou générer une note de frais '; + // We propose to generate the invoice and some template + $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=10"); + $r.=$doc_gen->IOValue().'
'; + } return $r; } diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index bca5525ee..7e88a8227 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -27,7 +27,7 @@ require_once('class_acc_ledger.php'); require_once('class_acc_compute.php'); require_once('class_anc_operation.php'); require_once('user_common.php'); - +require_once('class_acc_payment.php'); /*!\brief Handle the ledger of sold, * * @@ -99,7 +99,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { for ($i=0;$i< $nb_item;$i++) { if ( strlen(trim(${'e_march'.$i}))== 0) continue; /* check if amount are numeric and */ - if ( isNumber(${'e_march'.$i.'_sell'}) == 0 ) + if ( isNumber(${'e_march'.$i.'_price'}) == 0 ) throw new AcException('La fiche '.${'e_march'.$i}.'a un montant invalide ['.${'e_march'.$i}.']',6); if ( isNumber(${'e_quant'.$i}) == 0 ) throw new AcException('La fiche '.${'e_march'.$i}.'a une quantité invalide ['.${'e_quant'.$i}.']',7); @@ -123,6 +123,11 @@ class Acc_Ledger_Sold extends Acc_Ledger { } if ( $nb == 0 ) throw new AcException('Il n\'y a aucune marchandise',12); + //------------------------------------------------------ + // The "Paid By" check + //------------------------------------------------------ + if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp}); + } public function save() { @@ -155,13 +160,13 @@ class Acc_Ledger_Sold extends Acc_Ledger { /* Save all the items without vat */ for ($i=0;$i< $nb_item;$i++) { if ( strlen(trim(${'e_march'.$i})) == 0 ) continue; - if ( ${'e_march'.$i.'_sell'} == 0 ) continue; + if ( ${'e_march'.$i.'_price'} == 0 ) continue; if ( ${'e_quant'.$i} == 0 ) continue; /* First we save all the items without vat */ $fiche=new fiche($this->db); $fiche->get_by_qcode(${"e_march".$i}); - $amount=bcmul(${'e_march'.$i.'_sell'},${'e_quant'.$i}); + $amount=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i}); $tot_amount+=$amount; $acc_operation=new Acc_Operation($this->db); $acc_operation->date=$e_date; @@ -288,10 +293,67 @@ class Acc_Ledger_Sold extends Acc_Ledger { } else /* Generate an invoice and save it into the database */ if ( isset($_POST['gen_invoice'])) { - echo $this->create_invoice($internal,$p_array); + echo $this->create_document($internal,$p_array); echo '
'; } + //---------------------------------------- + // Save the payer + //---------------------------------------- + if ( $e_mp != 0 ) { + /* mp */ + $mp=new Acc_Payment($this->db,$e_mp); + $mp->load(); + + /* fiche */ + $fqcode=${'e_mp_qcode_'.$e_mp}; + $acfiche = new fiche($this->db); + $acfiche->get_by_qcode($fqcode); + + /* jrnx */ + $acseq=NextSequence($this->db,'s_grpt'); + $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger')); + $acinternal=$acjrn->compute_internal_code($acseq); + + /* Insert paid by */ + $acc_pay=new Acc_Operation($this->db); + $acc_pay->date=$e_date; + $acc_pay->poste=$acfiche->strAttribut(ATTR_DEF_ACCOUNT); + $acc_pay->qcode=$fqcode; + $acc_pay->amount=abs(round($tot_debit,2)); + $acc_pay->desc=$e_comm; + $acc_pay->grpt=$acseq; + $acc_pay->jrn=$mp->get_parameter('ledger'); + $acc_pay->periode=$periode; + $acc_pay->type='d'; + $acc_pay->insert_jrnx(); + + /* Insert supplier */ + $acc_pay=new Acc_Operation($this->db); + $acc_pay->date=$e_date; + $acc_pay->poste=$poste; + $acc_pay->qcode=$e_client; + $acc_pay->amount=abs(round($tot_debit,2)); + $acc_pay->desc=$e_comm; + $acc_pay->grpt=$acseq; + $acc_pay->jrn=$mp->get_parameter('ledger'); + $acc_pay->periode=$periode; + $acc_pay->type='c'; + $acc_pay->insert_jrnx(); + /* insert into jrn */ + $acc_pay->insert_jrn(); + $acjrn->grpt_id=$acseq; + $acjrn->update_internal_code($acinternal); + + $r1=$this->get_id($internal); + $r2=$this->get_id($acinternal); + + /* Reconcialiation */ + $rec=new Acc_Reconciliation($this->db); + $rec->set_jr_id($r1); + $rec->insert($r2); + } + } catch (Exception $e) { @@ -555,7 +617,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { // Code id, price & vat code //-- $march=(isset(${"e_march$i"}))?${"e_march$i"}:""; - $march_sell=(isset(${"e_march".$i."_sell"}))?${"e_march".$i."_sell"}:""; + $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""; $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:""; @@ -602,7 +664,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { $Price->table=1; $Price->size=9; $Price->javascript="onBlur='compute_sold($i)'"; - $r.=$Price->IOValue("e_march".$i."_sell",$march_sell); + $r.=$Price->IOValue("e_march".$i."_price",$march_price); // vat label //-- $select_tva=make_array($this->db,"select tva_id,tva_label from tva_rate order by tva_rate desc",0); @@ -657,6 +719,15 @@ class Acc_Ledger_Sold extends Acc_Ledger { // Set correctly the REQUEST param for jrn_type $r.=widget::hidden('jrn_type','VEN'); + //---------------------------------------------------------------------- + /* Paid By */ + $r.='
'; + $r.=' Payé par '; + $mp=new Acc_Payment($this->db); + $mp->set_parameter('type','VEN'); + $r.=$mp->select(); + $r.='
'; + $r.=widget::button('add_item','Ajout article', ' onClick="ledger_sold_add_row()"'); $r.=widget::submit("view_invoice","Enregistrer"); $r.=widget::reset('Effacer '); @@ -734,7 +805,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { $oTva->set_parameter('id',$idx_tva); $oTva->load(); $op=new Acc_Compute(); - $amount=bcmul(${"e_march".$i."_sell"},${'e_quant'.$i}); + $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i}); $op->set_parameter("amount",$amount); $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate')); @@ -754,7 +825,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { $r.=$fiche_name; $r.=''; $r.=''; - $r.=${"e_march".$i."_sell"}; + $r.=${"e_march".$i."_price"}; $r.=''; $r.=''; $r.=${"e_quant".$i}; @@ -834,10 +905,24 @@ class Acc_Ledger_Sold extends Acc_Ledger { $r.=widget::hidden('e_comm',$e_comm); $r.=widget::hidden('e_date',$e_date); $r.=widget::hidden('e_ech',$e_ech); + $e_mp=(isset($e_mp))?$e_mp:0; + $r.=widget::hidden('e_mp',$e_mp); + /* Paid by */ + /* if the paymethod is not 0 and if a quick code is given */ + if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 ) { + $r.=widget::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp}); + + /* needed for generating a invoice */ + $r.=widget::hidden('qcode_dest',${'e_mp_qcode_'.$e_mp}); + + $r.="Payé par ".${'e_mp_qcode_'.$e_mp}; + $r.='
'; + } + $r.=widget::hidden('jrn_type',$jrn_type); for ($i=0;$i < $nb_item;$i++) { $r.=widget::hidden("e_march".$i,${"e_march".$i}); - $r.=widget::hidden("e_march".$i."_sell",${"e_march".$i."_sell"}); + $r.=widget::hidden("e_march".$i."_price",${"e_march".$i."_price"}); $r.=widget::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"}); $r.=widget::hidden("e_quant".$i,${"e_quant".$i}); } @@ -882,27 +967,6 @@ class Acc_Ledger_Sold extends Acc_Ledger { $r.='
'; return $r; } - /*!\brief create the invoice and saved it as attachment to the - *operation, - *\param $internal is the internal code - *\param $p_array is normally the $_POST - *\return a string - */ - function create_invoice($internal,$p_array) { - extract ($p_array); - $doc=new Document($this->db); - $doc->f_id=$e_client; - $doc->md_id=$gen_doc; - $doc->ag_id=0; - $str_file=$doc->Generate(); - // Move the document to the jrn - $doc->MoveDocumentPj($internal); - // Update the comment with invoice number - $sql="update jrn set jr_comment='Facture ".$doc->d_number."' where jr_internal='$internal'"; - ExecSql($this->db,$sql); - return '

'.$str_file.'

'; - - } /*!\brief update the payment diff --git a/include/class_acc_payment.php b/include/class_acc_payment.php new file mode 100644 index 000000000..e7cb6ab24 --- /dev/null +++ b/include/class_acc_payment.php @@ -0,0 +1,339 @@ + id ( Primary key ) + - mp_lib ==> lib (label) + - mp_type ==> type (type of the ledger ACH or VEN ) + - mp_jrn_def_id ==> ledger (Number of the ledger where to save) + - mp_fd_id ==> fiche_def (fiche class to use) + - mp_qcode ==> qcode (quick_code of the card) + * + */ +class Acc_Payment +{ + + private static $variable=array("id"=>"mp_id", + "lib"=>"mp_lib", + "qcode"=>"mp_qcode", + "type"=>"mp_type", + "ledger"=>"mp_jrn_def_id", + "fiche_def"=>"mp_fd_id"); + + + private $mp_lib; + private $mp_qcode; + private $mp_type; + private $mp_jrn_def_if; + + private $mp_fd_id; + + function __construct ($p_cn,$p_init=0) { + $this->cn=$p_cn; + $this->mp_id=$p_init; + } + public function get_parameter($p_string) { + if ( array_key_exists($p_string,self::$variable) ) { + $idx=self::$variable[$p_string]; + return $this->$idx; + } + else + exit (__FILE__.":".__LINE__.'Erreur attribut inexistant'); + } + public function set_parameter($p_string,$p_value) { + if ( array_key_exists($p_string,self::$variable) ) { + $idx=self::$variable[$p_string]; + $this->$idx=$p_value; + } + else + exit (__FILE__.":".__LINE__.'Erreur attribut inexistant'); + + + } + public function get_info() { return var_export(self::$variable,true); } + public function verify() { + // Verify that the elt we want to add is correct + } + public function save() { + /* please adapt */ + if ( $this->get_parameter("id") == 0 ) + $this->insert(); + else + $this->update(); + } + + public function insert() { + if ( $this->verify() != 0 ) return; + /* please adapt + $sql="insert into tva_rate (tva_label,tva_rate,tva_comment,tva_poste) ". + " values ($1,$2,$3,$4) returning tva_id"; + $res=ExecSqlParam($this->cn, + $sql, + array($this->tva_label, + $this->tva_rate, + $this->tva_comment, + $this->tva_poste) + ); + $this->tva_id=pg_fetch_result($res,0,0); + */ + } + + public function update() { + if ( $this->verify() != 0 ) return; + + $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_type=$3,mp_jrn_def_id=$4,mp_fd_id=$5 ". + " where mp_id = $6"; + $res=ExecSqlParam($this->cn, + $sql, + array($this->mp_lib, + $this->mp_qcode, + $this->mp_type, + $this->mp_jrn_def_id, + $this->mp_fd_id, + $this->mp_id) + ); + if ( strlen (trim($this->mp_jrn_def_id))==0) + ExecSqlParam($this->cn, + 'update mod_payment '. + 'set mp_jrn_def_id = null where mp_id=$1', + array($this->mp_id)); + if ( strlen (trim($this->mp_qcode))==0) + ExecSqlParam($this->cn, + 'update mod_payment '. + 'set mp_qcode = null where mp_id=$1', + array($this->mp_id)); + if ( strlen (trim($this->mp_fd_id))==0) + ExecSqlParam($this->cn, + 'update mod_payment '. + 'set mp_fd_id = null where mp_id=$1', + array($this->mp_id)); + + } + + public function load() { + $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,mp_type from mod_payment '. + ' where mp_id = $1'; + $res=ExecSqlParam($this->cn, + $sql, + array($this->mp_id) + ); + + if ( pg_NumRows($res) == 0 ) return; + $row=pg_fetch_array($res,0); + foreach ($row as $idx=>$value) { $this->$idx=$value; } + } + public function delete() { +/* $sql="delete from tva_rate where tva_id=$1"; + $res=ExecSqlParam($this->cn,$sql,array($this->tva_id)); +*/ + } + /*!\brief retrieve all the data for a certain type + *\param non + *\return an array of row + */ + public function get_all() { + $sql='select mp_id '. + ' from mod_payment '. + ' where mp_type=$1'; + $array=get_array($this->cn,$sql,array($this->mp_type)); + $ret=array(); + if ( !empty($array) ) { + foreach ($array as $row) { + $t=new Acc_Payment($this->cn,$row['mp_id']); + $t->load(); + $ret[]=$t; + } + } + return $ret; + } + /*!\brief retrieve all the data for a certain type but filter on the + *valid record (jrn and fd not null + *\param non + *\return an array of row + */ + public function get_valide() { + $sql='select mp_id '. + ' from mod_payment '. + ' where mp_type=$1 and mp_jrn_def_id is not null and '. + ' (mp_fd_id is not null or mp_qcode is not null)'; + $array=get_array($this->cn,$sql,array($this->mp_type)); + $ret=array(); + if ( !empty($array) ) { + foreach ($array as $row) { + $t=new Acc_Payment($this->cn,$row['mp_id']); + $t->load(); + $ret[]=$t; + } + } + return $ret; + } + + public function row() { + //--------------------------------------------------------------------------- + // Common variable + $td='';$etd='';$tr='';$etr='';$th='';$eth=''; + + $r=''; + $r.=$td.$this->mp_lib.$etd; + if ( $this->mp_fd_id != NULL && $this->mp_fd_id !=0) { + $fiche=new Fiche_Def($this->cn,$this->mp_fd_id); + $fiche->Get(); + $r.=$td.$fiche->label.$etd; + }else + $r.=$td.$etd; + $jrn=new Acc_Ledger($this->cn,$this->mp_jrn_def_id); + $r.=$td.$jrn->get_name().$etd; + if ( strlen(trim($this->mp_qcode)) != 0 ) { + $f=new Fiche($this->cn); + $f->get_by_qcode($this->mp_qcode); + $r.=$td.$f->strAttribut(ATTR_DEF_NAME).$etd; + + }else + $r.=$td.$etd; + return $r; + } + /*!\brief return a string with a form (into a table) + *\param none + *\return a html string + */ + public function form() { + $td='';$etd='';$tr='';$etr='';$th='';$eth=''; + $r=''; + $r.=widget::hidden('id',$this->mp_id); + $r.=''; + $r.=$tr.$td.'Libellé'.$etd; + $r.=$td; + $r.=$this->mp_lib; + $r.=$etd.$etr; + $r.=$tr.$td; + $r.='Type de fiche '.$etd; + $array=make_array($this->cn,'select fd_id,fd_label from fiche_def join fiche_def_ref '. + ' using (frd_id) where frd_id in (25,4) order by fd_label'); + $fd=new widget('select'); + $fd->name='mp_fd_id'; + $fd->value=$array; + $fd->selected=$this->mp_fd_id; + $r.=$td.$fd->IOValue(); + $r.=$etd; + $r.=$tr.$td.'Enregistre dans le journal '.$etd; + $array=make_array($this->cn,'select jrn_def_id,jrn_def_name from '. + ' jrn_def where jrn_def_type = \'ODS\' or jrn_def_type=\'FIN\''); + $jrn=new widget('select'); + $jrn->value=$array; + $jrn->name='mp_jrn_def_id'; + $jrn->selected=(isset ($this->mp_jrn_def_id))?$this->mp_jrn_def_id:0; + $r.=$td.$jrn->IOValue().$etd; + $r.=$etr.$tr; + $r.=$td.'Avec la fiche'.$etd; + $f=new widget('js_search_only'); + $f->name='mp_qcode'; + $f->extra='frd_id in (25,4)'; + $f->extra2='Recherche'; + $f->value=(isset($this->mp_qcode))?$this->mp_qcode:''; + $r.=$td.$f->IOValue().$etd; + $s=new widget('span'); + $r.=$td.$s->IOValue('mp_qcode_label'); + $r.='
'; + return $r; + + } + /*!\brief show several lines with radio button to select the payment + *method we want to use, the $_POST['e_mp'] will be set + *\param none + *\return html string + */ + public function select() { + $r=''; + $array=$this->get_valide(); + $r.=widget::hidden('gDossier',dossier::id()); + $r.='
    '; + $r.='
  1. Paiement encodé plus tard'; + if ( empty($array ) == false ){ + foreach ($array as $row) { + $f=''; + /* if the qcode is null the propose a search button to select + the card */ + if ( $row->mp_qcode==NULL) { + $a=new widget('js_search_only'); + $a->extra=$row->mp_fd_id; + $a->extra2='Recherche'; + $a->name='e_mp_qcode_'.$row->mp_id; + $s=new widget('span'); + $s->name=$a->name.'_label'; + $f=$a->IOValue().$s->IOValue(); + }else { + /* if the qcode is not null then add a hidden variable with + the qcode */ + + $fiche=new fiche($this->cn); + $fiche->get_by_qcode($row->mp_qcode); + $f=widget::hidden('e_mp_qcode_'.$row->mp_id,$row->mp_qcode); + + $f.=$fiche->strAttribut(ATTR_DEF_NAME); + } + $r.='
  2. '; + $r.=' payement par '.$row->mp_lib.' - fiche '.$f; + + /* Show in which ledger the operation will be saved */ + $jrn=new Acc_Ledger($this->cn,$row->mp_jrn_def_id); + $r.=' dans le journal '.$jrn->get_name(); + + } + } + $r.='
'; + return $r; + } + + /*!\brief convert an array into an Acc_Payment object + *\param array to convert + */ + public function from_array($p_array) { + $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','mp_type'); + foreach ($idx as $l) + if (isset($p_array[$l])) $this->$l=$p_array[$l]; + } + /*!\brief test function + */ + static function test_me() { + echo JS_SEARCH_CARD; + $cn=DbConnect(dossier::id()); + $ac=new Acc_Payment($cn); + $ac->set_parameter('type','ACH'); + echo '
'; + echo $ac->select(); + echo widget::submit('go','go'); + echo '
'; + if ( isset($_POST['go'])) + print_r($_POST); + } + +} + + diff --git a/include/class_action.php b/include/class_action.php index 16b85c26e..39de07f6f 100644 --- a/include/class_action.php +++ b/include/class_action.php @@ -261,7 +261,8 @@ class action $w->name='qcode_exp'; $w->value=($this->f_id_exp != 0)?$this->qcode_exp:""; $w->label=""; - $w->extra='4,8,9,14,16'; + $w->extra='frd_id in (14,25,8,9,16)'; + $w->extra2='Recherche'; $sp= new widget("span"); $h_agrefid=new widget('hidden'); // destination @@ -270,7 +271,8 @@ class action $wdest->name='qcode_dest'; $wdest->value=($this->f_id_dest != 0)?$this->qcode_dest:""; $wdest->label=""; - $wdest->extra='4,8,9,14,16'; + $wdest->extra='frd_id in (14,25,8,9,16)'; + $wdest->extra2='Recherche'; $spdest= new widget("span"); $h_agrefid=new widget('hidden'); $str_ag_ref="".(($this->ag_ref != "")?$this->ag_ref:" Nouveau ").""; diff --git a/include/class_document.php b/include/class_document.php index 50d75204a..5d1985299 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -124,7 +124,7 @@ class Document $file_to_parse=$filename; // affect a number $this->d_number=NextSequence($this->db,"seq_doc_type_".$row['md_type']); - + echo_debug(__FILE__,__LINE__,"seq_doc_type_".$row['md_type'].' = '.$this->d_number); // parse the document - return the doc number ? $this->ParseDocument($dirname,$file_to_parse,$type); @@ -190,7 +190,7 @@ class Document { if ( mkdir($temp_dir) == false ) { - echo "Ne peut pas cr�er le r�pertoire ".$temp_dir; + echo "Ne peut pas créer le répertoire ".$temp_dir; exit(); } } @@ -224,16 +224,18 @@ class Document //read the file while(! feof($h)) { + echo_debug(__FILE__,__LINE__,'Read a line'); // replace the tag $buffer=fgets($h); // search in the buffer the magic << and >> // while ereg finds something to replace while ( eregi ($regex,$buffer,$f) ) { - + echo_debug(__FILE__,__LINE__,'Search for a regex'); echo_debug('class_document',__LINE__,'var_export '.var_export( $f,true)); foreach ( $f as $pattern ) { + echo_debug(__FILE__,__LINE__,'for each pattern '.$pattern); echo_debug('class_document',__LINE__, "pattern"); echo_debug('class_document',__LINE__, var_export($pattern,true)); $to_remove=$pattern; @@ -244,11 +246,7 @@ class Document // if the pattern if found we replace it $value=$this->Replace($pattern); - - // if the document is OOo, we need to transform accentuate letters - if ( $p_type=='OOo' ) - $value = utf8_encode($value); - + if ( strpos($value,'ERROR') != false ) $value=""; // replace into the $buffer // take the position in the buffer $pos=strpos($buffer,$to_remove); @@ -475,8 +473,8 @@ class Document */ function Replace($p_tag) { - $p_tag=strtoupper($p_tag); - $p_tag=str_replace('=','',$p_tag); + $p_tag=strtoupper($p_tag); + $p_tag=str_replace('=','',$p_tag); $r="Tag inconnu"; static $counter=0; switch ($p_tag) @@ -596,6 +594,18 @@ class Document $tiers->get_by_qcode($qcode,false); $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER); break; + case 'CUST_BANQUE_NO': + $tiers=new fiche($this->db); + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; + $tiers->get_by_qcode($qcode,false); + $r=$tiers->strAttribut(ATTR_DEF_BQ_NO); + break; + case 'CUST_BANQUE_NAME': + $tiers=new fiche($this->db); + $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client']; + $tiers->get_by_qcode($qcode,false); + $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME); + break; // Marchandise in $_POST['e_march*'] // \see user_form_achat.php or user_form_ven.php @@ -642,7 +652,7 @@ class Document // check if the march exists if ( ! isset (${$id})) return ""; // check that something is sold - if ( ${'e_march'.$counter.'_sell'} != 0 && ${'e_quant'.$counter} != 0 ) + if ( ${'e_march'.$counter.'_price'} != 0 && ${'e_quant'.$counter} != 0 ) { $f=new fiche($this->db); $f->get_by_qcode(${$id},false); @@ -652,7 +662,7 @@ class Document case 'VEN_ART_PRICE': extract ($_POST); - $id='e_march'.$counter.'_sell' ; + $id='e_march'.$counter.'_price' ; if ( !isset (${$id}) ) return ""; $r=${$id}; break; @@ -674,7 +684,7 @@ class Document if ( !isset (${$id}) ) return ""; if ( ${$id} == -1 ) return ""; $qt='e_quant'.$counter; - $price='e_march'.$counter.'_sell' ; + $price='e_march'.$counter.'_price' ; if ( ${$price} == 0 || ${$qt} == 0 || strlen(trim( $price )) ==0 || strlen(trim($qt)) ==0) @@ -696,7 +706,7 @@ class Document case 'TVA_AMOUNT': extract ($_POST); $qt='e_quant'.$counter; - $price='e_march'.$counter.'_sell' ; + $price='e_march'.$counter.'_price' ; $tva='e_march'.$counter.'_tva_id'; if ( !isset (${'e_march'.$counter}) ) return ""; // check that something is sold @@ -715,7 +725,7 @@ class Document case 'VEN_ART_TVA': extract ($_POST); $qt='e_quant'.$counter; - $price='e_march'.$counter.'_sell' ; + $price='e_march'.$counter.'_price' ; $tva='e_march'.$counter.'_tva_id'; if ( !isset (${'e_march'.$counter}) ) return ""; // check that something is sold @@ -734,7 +744,7 @@ class Document case 'VEN_ART_TVAC': extract ($_POST); $qt='e_quant'.$counter; - $price='e_march'.$counter.'_sell' ; + $price='e_march'.$counter.'_price' ; $tva='e_march'.$counter.'_tva_id'; if ( !isset (${'e_march'.$counter}) ) return ""; // check that something is sold @@ -758,9 +768,9 @@ class Document $id='e_quant'.$counter; if ( !isset (${$id}) ) return ""; // check that something is sold - if ( ${'e_march'.$counter.'_sell'} == 0 + if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0 - || strlen(trim( ${'e_march'.$counter.'_sell'} )) ==0 + || strlen(trim( ${'e_march'.$counter.'_price'} )) ==0 || strlen(trim(${'e_quant'.$counter})) ==0 ) return ""; $r=${$id}; @@ -768,13 +778,13 @@ class Document case 'VEN_HTVA': extract ($_POST); - $id='e_march'.$counter.'_sell' ; + $id='e_march'.$counter.'_price' ; $quant='e_quant'.$counter; if ( !isset (${$id}) ) return ""; // check that something is sold - if ( ${'e_march'.$counter.'_sell'} == 0 || ${'e_quant'.$counter} == 0 - || strlen(trim( ${'e_march'.$counter.'_sell'} )) ==0 + if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0 + || strlen(trim( ${'e_march'.$counter.'_price'} )) ==0 || strlen(trim(${'e_quant'.$counter})) ==0) return ""; /*!\todo verify that price and quant are numeric @@ -787,13 +797,13 @@ class Document case 'VEN_TVAC': extract ($_POST); - $id='e_march'.$counter.'_sell' ; + $id='e_march'.$counter.'_price' ; $quant='e_quant'.$counter; // if it is exist if ( ! isset(${$id})) return ""; // check that something is sold - if ( ${'e_march'.$counter.'_sell'} == 0 || ${'e_quant'.$counter} == 0 ) + if ( ${'e_march'.$counter.'_price'} == 0 || ${'e_quant'.$counter} == 0 ) return ""; /*!\todo verify that price and quant are numeric */ @@ -814,7 +824,7 @@ class Document $sum=0.0; for ($i=0;$i<$nb_item;$i++) { - $sell='e_march'.$i.'_sell'; + $sell='e_march'.$i.'_price'; $qt='e_quant'.$i; echo_debug('class_document',__LINE__,'sell :'.$sell.' qt = '.$qt); @@ -842,7 +852,7 @@ class Document $tva=GetTvaRate($this->db,${'e_march'.$i.'_tva_id'}); $tva_rate=( $tva == null || $tva == 0 )?0.0:$tva['tva_rate']; echo_debug('class_document',__LINE__,' :'.$i.' sur '.$nb_item); - $sell=${'e_march'.$i.'_sell'}; + $sell=${'e_march'.$i.'_price'}; $qt=${'e_quant'.$i}; echo_debug('class_document',__LINE__,'sell :'.$sell.' qt = '.$qt); @@ -860,7 +870,7 @@ class Document $tva=GetTvaRate($this->db,${'e_march'.$i.'_tva_id'}); $tva_rate=( $tva == null || $tva == 0 )?0.0:$tva['tva_rate']; echo_debug('class_document',__LINE__,' :'.$i.' sur '.$nb_item); - $sell=${'e_march'.$i.'_sell'}; + $sell=${'e_march'.$i.'_price'}; $qt=${'e_quant'.$i}; echo_debug('class_document',__LINE__,'sell :'.$sell.' qt = '.$qt); diff --git a/include/class_document_modele.php b/include/class_document_modele.php index 32798bb98..3aca40d2d 100644 --- a/include/class_document_modele.php +++ b/include/class_document_modele.php @@ -172,8 +172,8 @@ class Document_modele { } catch (Exception $e) { - echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage); - rollback($p_cn); + echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage()); + rollback($this->cn); return ; } } @@ -289,7 +289,7 @@ class Document_modele { $start->value="0"; $r.=" Numerotation commence a ".$start->IOValue().""; - $r.='Si vous laissez à 0, la numérotation ne changera pas'; + $r.='Si vous laissez à 0, la numérotation ne changera pas, la prochaine facture sera n+1, n étant le n° que vous avez donné'; $r.=""; $r.=''; $r.=widget::submit('add_document','Ajout'); diff --git a/include/class_fiche_def.php b/include/class_fiche_def.php index c6f5c3110..bedbfad04 100644 --- a/include/class_fiche_def.php +++ b/include/class_fiche_def.php @@ -193,7 +193,7 @@ class fiche_def { // Set the value of fiche_def.fd_create_account // automatic creation for 'poste comptable' - if ( isset($p_create)) + if ( isset($p_create) && strlen(trim($p_class_base)) != 0) $p_create='true'; else $p_create='false'; diff --git a/include/class_pre_op_ach.php b/include/class_pre_op_ach.php index 6a50ff64c..35d28329c 100644 --- a/include/class_pre_op_ach.php +++ b/include/class_pre_op_ach.php @@ -44,7 +44,7 @@ class Pre_op_ach extends Pre_operation_detail { for ($i=0;$i<$this->operation->nb_item;$i++) { $march="e_march".$i; $this->$march=$_POST['e_march'.$i]; - $this->{"e_march".$i."_buy"}=$_POST['e_march'.$i."_buy"]; + $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"]; $this->{"e_march".$i."_tva_id"}=$_POST['e_march'.$i."_tva_id"]; $this->{"e_march".$i."_tva_amount"}=$_POST['e_march'.$i."_tva_amount"]; $this->{"e_quant".$i}=$_POST['e_quant'.$i]; @@ -75,7 +75,7 @@ class Pre_op_ach extends Pre_operation_detail { ' values '. "('%s',%.2f,%d,%f,'%s',%d,%f)", $this->{"e_march".$i}, - $this->{"e_march".$i."_buy"}, + $this->{"e_march".$i."_price"}, $this->{"e_march".$i."_tva_id"}, $this->{"e_quant".$i}, 't', @@ -102,7 +102,7 @@ class Pre_op_ach extends Pre_operation_detail { $array+=array('e_client'=>$row['opd_poste']); } else { $array+=array("e_march".$count=>$row['opd_poste'], - "e_march".$count."_buy"=>$row['opd_amount'], + "e_march".$count."_price"=>$row['opd_amount'], "e_march".$count."_tva_id"=>$row['opd_tva_id'], "e_march".$count."_tva_amount"=>$row['opd_tva_amount'], "e_quant".$count=>$row['opd_quantity'] diff --git a/include/class_pre_op_ven.php b/include/class_pre_op_ven.php index 2b9bf991b..b6e1d26fd 100644 --- a/include/class_pre_op_ven.php +++ b/include/class_pre_op_ven.php @@ -43,7 +43,7 @@ class Pre_op_ven extends Pre_operation_detail { for ($i=0;$i<$this->operation->nb_item;$i++) { $march="e_march".$i; $this->$march=$_POST['e_march'.$i]; - $this->{"e_march".$i."_sell"}=$_POST['e_march'.$i."_sell"]; + $this->{"e_march".$i."_price"}=$_POST['e_march'.$i."_price"]; $this->{"e_march".$i."_tva_id"}=$_POST['e_march'.$i."_tva_id"]; $this->{"e_quant".$i}=$_POST['e_quant'.$i]; @@ -74,7 +74,7 @@ class Pre_op_ven extends Pre_operation_detail { ' values '. "('%s',%.2f,%d,%f,'%s',%d)", $this->{"e_march".$i}, - $this->{"e_march".$i."_sell"}, + $this->{"e_march".$i."_price"}, $this->{"e_march".$i."_tva_id"}, $this->{"e_quant".$i}, 'f', @@ -101,7 +101,7 @@ class Pre_op_ven extends Pre_operation_detail { $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."_price"=>$row['opd_amount'], "e_march".$count."_tva_id"=>$row['opd_tva_id'], "e_quant".$count=>$row['opd_quantity'] ); diff --git a/include/class_widget.php b/include/class_widget.php index d48d18a61..6d773e359 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -693,4 +693,5 @@ class widget { $r='?'; return $r; } + } diff --git a/include/constant.php b/include/constant.php index 4748fdd60..077b0a9e6 100644 --- a/include/constant.php +++ b/include/constant.php @@ -25,9 +25,7 @@ */ require_once ('config.inc.php'); - - -define ("DBVERSION",52); +define ("DBVERSION",53); define ("MAX_COMPTE",4); define ('MAX_BUD_DETAIL',20); @@ -121,6 +119,8 @@ define ("ALL_FICHE_DEF_REF", 1000); // fixed value for attr_def data define ("ATTR_DEF_ACCOUNT",5); define ("ATTR_DEF_NAME",1); +define ("ATTR_DEF_BQ_NO",3); +define ("ATTR_DEF_BQ_NAME",4); define ("ATTR_DEF_PRIX_ACHAT",7); define ("ATTR_DEF_PRIX_VENTE",6); define ("ATTR_DEF_TVA",2); @@ -142,6 +142,7 @@ define ("FICHE_TYPE_VENTE",1); define ("FICHE_TYPE_FOURNISSEUR",8); define ("FICHE_TYPE_FIN",4); define ("FICHE_TYPE_CONTACT",16); +define ("FICHE_TYPE_EMPL",25); define ("FICHE_TYPE_ADM_TAX",14); define ("FICHE_TYPE_ACH_MAR",2); define ("FICHE_TYPE_ACH_SER",3); diff --git a/include/fiche_def.inc.php b/include/fiche_def.inc.php index 8f311bf52..3fcff91b0 100644 --- a/include/fiche_def.inc.php +++ b/include/fiche_def.inc.php @@ -22,7 +22,7 @@ require_once("class_fiche_def.php"); /*! \file * \brief Let customise the fiche_def_ref for the user */ - +echo '
'; // record change if ( isset ($_POST['confirm_mod'])) { extract ($_POST); @@ -75,3 +75,4 @@ if ( isset ($_POST['mod']) ) echo ''; echo '
'; } +echo '
'; \ No newline at end of file diff --git a/include/payment_middle.inc.php b/include/payment_middle.inc.php new file mode 100644 index 000000000..43a1f39a1 --- /dev/null +++ b/include/payment_middle.inc.php @@ -0,0 +1,125 @@ +';$etd='';$tr='';$etr='';$th='';$eth=''; + +/*!\file + * \brief payment mode + */ + +echo '
'; + +//---------------------------------------------------------------------- +// change +if ( $sb=='change') { + echo JS_SEARCH_CARD; + echo JS_AJAX_FICHE; + echo JS_PROTOTYPE; + if ( !isset($_GET['id'])) exit; + $row=new Acc_Payment($cn,$_GET['id']); + $row->load(); + echo '
'; + echo dossier::hidden(); + echo widget::hidden('p_jrn',0); + echo widget::hidden('p_action','divers'); + echo widget::hidden('sa','mp'); + echo widget::hidden('sb','save'); + echo widget::hidden('mp_type',$row->get_parameter('type')); + echo widget::hidden('mp_lib',$row->get_parameter('lib')); + + echo $row->form(); + echo widget::submit('save','Sauve'); + echo widget::button_href('Retour sans sauvez', + '?p_action=divers&sa=mp&'.dossier::get() + ); + echo '
'; + exit(); +} +//---------------------------------------------------------------------- +// Save the change +// +if ( $sb=='save'){ + $row=new Acc_Payment($cn,$_POST ['id']); + $row->from_array($_POST); + $row->update(); + +} + +//---------------------------------------------------------------------- +// LEDGER PURCHASE +//---------------------------------------------------------------------- + +echo '
'; +echo 'Journaux d\' achat'; +/* Get the data from database */ +$mp=new Acc_Payment($cn); +$mp->set_parameter('type','ACH'); +$array=$mp->get_all(); +/* if there are data show them in a table */ +if ( ! empty ($array)) { + echo ''; + echo $tr.$th.'Libellé'.$eth.$th.'Type de fiche' + .$eth.$th.'enregistré dans le journal'.$eth. + $th.' Avec la fiche'.$eth.$th.'Aciotn'.$eth.$etr; + foreach ($array as $row) { + echo $tr; + echo $row->row(); + echo $td.widget::button_href('Modifie','?p_action=divers&sa=mp&sb=change&'.dossier::get(). + '&id='.$row->get_parameter('id')); + echo $etr; + + } + echo '
'; +} +echo '
'; + +//---------------------------------------------------------------------- +// LEDGER SOLD +//---------------------------------------------------------------------- + +echo '
'; +echo 'Journaux de vente'; +$mp=new Acc_Payment($cn); +$mp->set_parameter('type','VEN'); +$array=$mp->get_all(); +/* if there are data show them in a table */ +if ( ! empty ($array)) { + echo ''; + echo $tr.$th.'Libellé'.$eth.$th.'Type de fiche' + .$eth.$th.'enregistré dans le journal'.$eth. + $th.' Avec la fiche'.$eth.$th.'Aciotn'.$eth.$etr; + foreach ($array as $row) { + echo $tr; + echo $row->row(); + echo $td.widget::button_href('Modifie','?p_action=divers&sa=mp&sb=change&'.dossier::get(). + '&id='.$row->get_parameter('id')); + echo $etr; + + } + echo '
'; +} + +echo '
'; +echo '
'; +?> \ No newline at end of file diff --git a/include/preference.php b/include/preference.php index 7dec74084..c940510d5 100644 --- a/include/preference.php +++ b/include/preference.php @@ -194,21 +194,25 @@ function ShowDevise($p_cn) $Res=ExecSql($p_cn,"select pm_id,pm_code,pm_rate from parm_money order by pm_code"); $Max=pg_NumRows($Res); - + $link='parametre.php?p_action=divers&sa=devise&'.dossier::get(); for ($i=0;$i<$Max;$i++) { $l_line=pg_fetch_array($Res,$i); echo ''; echo ''.$l_line['pm_code'].''; $l_rate=sprintf("% 10.6f",$l_line['pm_rate']); echo ''.$l_rate.''; - echo " Change"; - echo " Efface"; + echo " Change"; + echo " Efface"; echo ''; } echo '
'; echo ' '; echo ' '; + echo dossier::hidden(); +echo ''; +echo ''; +echo ''; echo ' '; echo '
'; echo ''; diff --git a/include/user_menu.php b/include/user_menu.php index b63e0a055..9d192793a 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -686,7 +686,7 @@ function ShowMenuParam($p_action="") $sub_menu=ShowItem(array( array('parametre.php?p_action=company&'.$s,'Sociétés','Parametre societe',1), - array('parametre.php?p_action=devise&'.$s,'Devises','Devise',2), + array('parametre.php?p_action=divers&'.$s,'Divers','Devise, moyen de paiement',2), array('parametre.php?p_action=tva&'.$s,'Tva','Taux & poste pour la TVA',3), array('parametre.php?p_action=poste&'.$s,'Poste Comptable','Poste comptable constant',4), array('parametre.php?p_action=pcmn&'.$s,'Plan Comptable','Modification du plan comptable',11), diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 2e38a3693..58330f904 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,3 +1,4 @@ begin; -insert into parameter values ('MY_STRICT','N'); -commit; \ No newline at end of file + + +commit;