noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Acc_Operation Class Reference

this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these table. More...

+ Inheritance diagram for Acc_Operation:
+ Collaboration diagram for Acc_Operation:

Public Member Functions

 __construct ($p_cn)
 constructor set automatically the attributes user and periode
 
 __toString ()
 
 display_jrnx_detail ($p_table)
 display_jrnx_detail : get the data from get_jrnx_data and return a string with HTML code
 
 find_tiers ($pn_jrn_id, $pn_jrnx_id, $p_code)
 Find the tiers of an operation , thanks the SQL prepared query prep_tiers and prep_counterpart.
 
 form_clone_operation ($p_id)
 create a form to recreate the operation and returns it, it works the same as when you want to correct an operation instead of confirming
 
 get ()
 retrieve data from jrnx and jrn
 
 get_amount ()
 return amount of the jr_id
 
 get_currency_amount ()
 retrieve amount in currency for the operation
 
 get_data ($p_grpt)
 Get data from jrnx where p_grpt=jrnx(j_grpt)
 
 get_info ()
 retrieve info from the jrn_info, create 2 new arrays obj->info->command and obj->info->other the columns are the idx
 
 get_internal ()
 Return the internal value, the property jr_id must be set before.
 
 get_jrnx_detail ()
 retrieve data from jrnx
 
 get_ledger ()
 return the jrn_def_id from jrn
 
 get_quant ()
 retrieve data from the table QUANT_*
 
 get_sum_other_tax ()
 get the sum of other tax linked to this operation
 
 insert_jrn ()
 Insert into the table Jrn, the amount is computed from jrnx thanks the group id ($p_grpt)
 
 insert_jrnx ()
 Insert into the table Jrn The needed data are :
 
 insert_related_action ($p_string)
 
 operation_update_comment ($p_text)
 add a comment to the operation (jrn.jr_text)
 
 operation_update_date_limit ($p_text)
 add a limit of payment to the operation (jrn.jr_ech)
 
 save_info ($p_info, $p_type)
 Save into jrn_info.
 
 seek_group ()
 retrieve the grpt_id from jrn for a jr_id
 
 seek_internal ($p_internal)
 search an operation thankx it internal code
 
 set_id ($p_id)
 set the operation id (jrn.jr_id)
 
 set_paid ()
 flag the operation as paid
 
 update_comment ($p_text)
 add a comment to the line (jrnx.j_text)
 
 update_receipt ()
 set the pj of a operation in jrn. the jr_id must be set
 

Static Public Member Functions

static select_operation_type ($p_status)
 Return a select object to choose the type of operation.
 
static test_me ()
 

Data Fields

 $amount
 
 $currency_id
 
 $currency_rate
 
 $currency_rate_ref
 
 $date
 
 $date_paid
 
 $db
 
 $debit
 
 $desc
 
 $echeance
 
 $f_id
 
 $grpt
 
 $jr_id
 
 $jr_internal
 
 $jr_optype
 
 $jrn
 
 $jrn_id
 
 $jrnx_id
 
 $mt
 
 $periode
 
 $pj
 
 $poste
 
 $qcode
 < Qcode of item
 
 $signature
 
 $type
 
 $user
 

Private Member Functions

 prepare_sql_counterpart ()
 prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn.jr_id , jrnx.j_id) must be provided
 
 prepare_sql_tiers ()
 prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn.jr_id , jrnx.j_id) must be provided
 

Detailed Description

this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these table.

Definition at line 33 of file acc_operation.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Operation::__construct ( $p_cn)

constructor set automatically the attributes user and periode

Parameters
$p_cnthe databse connection

Definition at line 67 of file acc_operation.class.php.

68 {
69 global $g_user;
70 $this->db=$p_cn;
71 $this->qcode="";
72 $this->user=$_SESSION[SESSION_KEY.'g_user'];
73 $this->periode=$g_user->get_periode();
74 $this->jr_id=0;
75 $this->jr_optype="NOR";
76 $this->amount=0;
77 $this->currency_rate=1;
78 $this->currency_rate_ref=1;
79 $this->currency_id=NULL;
80 }
global $g_user
if no group available , then stop
$op jr_id
$input_from user
$SecUser db

References $g_user, db, jr_id, and user.

Member Function Documentation

◆ __toString()

Acc_Operation::__toString ( )

Definition at line 82 of file acc_operation.class.php.

82 : string
83 {
84 $r=<<<EOF
85 Acc_Operation Object
86 [
87 db {$this->db}
88 qcode {$this->qcode}
89 user {$this->user}
90 periode {$this->periode}
91 jr_id {$this->jr_id}
92 jr_optype {$this->jr_optype}
93 amount {$this->amount}
94 currency_rate {$this->amount}
95 currency_rate_ref {$this->amount}
96 currency_id {$this->amount}
97 ]
98EOF;
99 return $r;
100
101 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $r, db, jr_id, and user.

◆ display_jrnx_detail()

Acc_Operation::display_jrnx_detail ( $p_table)

display_jrnx_detail : get the data from get_jrnx_data and return a string with HTML code

Parameters
table(=0no code for table,1 code for table,2 code for CSV)

Definition at line 473 of file acc_operation.class.php.

474 {
475 $show=$this->get_jrnx_detail();
476
477 $r='';
478 $r_notable='';
479 $csv="";
480 foreach ($show as $l)
481 {
482 $border="";
483 if ( $l['j_poste'] == $this->poste || ($l['j_qcode']==$this->qcode && trim($this->qcode) != ''))
484 $border=' class="highlight"';
485 $r.='<tr '.$border.'>';
486 $r.='<td>';
487 $a=$l['j_qcode'];
488
489 $r_notable.=$a;
490 $r.=$a;
491 $csv.='"'.$a.'";';
492 $r.='</td>';
493
494 $r.='<td '.$border.'>';
495 $a=$l['j_poste'];
496 $r_notable.=$a;
497 $r.=$a;
498 $csv.='"'.$a.'";';
499 $r.='</td>';
500
501 $r.='<td '.$border.'>';
502 // $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
503 $a=(noalyss_strlentrim($l['j_qcode'])==0)?$l['pcm_lib']:$l['vw_name'];
504 $r_notable.=$a;
505 $r.=h($a);
506 $csv.='"'.$a.'";';
507 $r.='</td>';
508
509 $r.='<td '.$border.'>';
510 $a=$l['j_montant'];
511 $r_notable.=$a;
512 $r.=$a;
513 $csv.=$a.';';
514 $r.='</td>';
515
516 $r.='<td '.$border.'>';
517 $a=$l['debit'];
518 $r_notable.=$a;
519 $r.=$a;
520 $csv.='"'.$a.'"';
521
522 $csv.="\r\n";
523 $r.='</td>';
524 $r.='<td '.$border.'>';
525 $a=($l['letter']!=-1)?$l['letter']:'';
526 $r_notable.=$a;
527 $r.=$a;
528 $csv.='"'.$a.'"';
529
530 $csv.="\r\n";
531 $r.='</td>';
532
533
534 $r.='</tr>';
535 }
536 switch ($p_table)
537 {
538 case 1:
539 return $r;
540 break;
541 case 0:
542 return $r_notable;
543 break;
544 case 2:
545 return $csv;
546 }
547 return "ERROR PARAMETRE";
548 }
noalyss_strlentrim($p_string)
h( $row[ 'oa_description'])
for($j=0;$j< $nb_row;$j++)($j%2==0)? 'even' $show
get_jrnx_detail()
retrieve data from jrnx

References $a, $csv, $l, $r, $show, get_jrnx_detail(), h, and noalyss_strlentrim().

+ Here is the call graph for this function:

◆ find_tiers()

Acc_Operation::find_tiers ( $pn_jrn_id,
$pn_jrnx_id,
$p_code )

Find the tiers of an operation , thanks the SQL prepared query prep_tiers and prep_counterpart.

Return a string with the quick_code

Parameters
type$pn_jrn_idpk of the table jrn (jrn.jr_id)
type$pn_jrnx_idpk of the table jrnx (jrnx.jr_id)
type$p_codequickcode
Returns
string

Definition at line 167 of file acc_operation.class.php.

168 {
169 static $p=0;
170 if ( $p == 0 ){
172 $this->prepare_sql_tiers();
173 $p=1;
174 }
175 $tiers="";
176 $res_tiers=$this->db->execute('prep_tiers',
177 array($pn_jrn_id,$pn_jrnx_id));
178 if ( Database::num_row($res_tiers) > 0) {
179 $atiers=Database::fetch_array($res_tiers);
180 $tiers=$atiers['ad_value'];
181 // If the found tiers has the same quickcode than the current
182 // card, it means it is a card of supplier or customer,
183 // so we must look for the countercard
184 if ($tiers == $p_code) {
185 $res_counterpart=$this->db->execute('prep_counterpart',
186 array($pn_jrn_id,$pn_jrnx_id));
187 $tiers="";
188 if ( Database::num_row($res_counterpart) > 0) {
189 $atiers=Database::fetch_array($res_counterpart);
190 $tiers=$atiers['ad_value'];
191 }
192 }
193 }
194 return $tiers;
195 }
$p
Definition calendar.php:9
prepare_sql_tiers()
prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn....
prepare_sql_counterpart()
prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn....
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows

References $p, $tiers, db, DatabaseCore\fetch_array(), DatabaseCore\num_row(), prepare_sql_counterpart(), and prepare_sql_tiers().

+ Here is the call graph for this function:

◆ form_clone_operation()

Acc_Operation::form_clone_operation ( $p_id)

create a form to recreate the operation and returns it, it works the same as when you want to correct an operation instead of confirming

See also
compta_ach.inc.php
compta_ven.inc.php
Parameters
$p_idstring DOMID of the form

Definition at line 901 of file acc_operation.class.php.

901 {
902 // retrieve all info about operation
903 $operation = $this->get_quant();
904 $array=$operation->compute_array();
905
906 global $g_user;
907 $a_code=$this->db->get_array("select code from v_menu_dependency vmd where me_code=$1 and p_id=$2",
908 array( $operation->signature,$g_user->get_profile()));
909 if ( empty ($a_code)) {
910 $r=_("Menu invalide");
911 return $r;
912 }
913
914 // Prepare the form
915 // select the menu where the operation will be duplicated
916 $r=sprintf('<form id="%s" method="POST" ACTION="%s">',$p_id,NOALYSS_URL."/do.php?".http_build_query([
917 "ac"=>$a_code[0]['code'],"gDossier"=>Dossier::id()
918 ]));
920 $default_currency=new Acc_Currency($this->db,0);
921 // select the menu where the operation will be duplicated
922
923 $r.="<p>";
924 $r.="<ul style=\"margin-left:2rem;padding-left:0;list-style:none;\">";
925 $r.=sprintf("<li>%s %s</li>",_("Date"),$operation->det->jr_pj_number);
926 $r.=sprintf("<li>%s %s</li>",_("Libellé"),$operation->det->jr_comment);
927 $r.=sprintf("<li>%s %s %s</li>",_("Montant "),nbm($operation->det->jr_montant),$default_currency->get_code());
928 // Add info if the operation using a currency
929 if ( $operation->det->currency_id != 0 ) {
930 $currency=$this->db->get_value("select cr_code_iso from currency where id=$1",[$operation->det->currency_id]);
931 $r.=sprintf("<li>%s %s</li>",_('Devise'),$currency);
932 $r.=sprintf("<li>%s %s</li>",_("Taux"),$operation->det->currency_rate);
933 $array['p_currency_code']=$operation->det->currency_id;
934 $array['p_currency_rate']=$operation->det->currency_rate;
935 }
936 $r.="</ul>";
937 $r.="</p>";
938 if (count($a_code) == 1 ) {
939 $r.=HtmlInput::hidden("ac",$a_code[0]['code']);
940 $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$a_code[0]['code']);
941
942 } else {
943 $select=new ISelect("ac");
944 $select->value=array();
945 $nb_code=count($a_code);
946
947 for ($i=0;$i<$nb_code;$i++) {
948 $select->value[]=array("label"=>$a_code[$i]['code'],"value"=>$a_code[$i]['code']);
949 }
950 $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$select->input());
951
952 }
953
954 $r.="</p>";
955
956 // For Misc Operation , if a card is given then there is no accounting
957 // modify amount with currency if not in default currency
958 if ( $operation->signature==="ODS") {
959 $nb_array = count($array);
960 for ($i = 0; $i < $nb_array; $i++) {
961 if (isset ($array["qc_" . $i]) && $array["qc_" . $i] != "") {
962 $array["poste" . $i] = "";
963 }
964
965 }
966 $idx=0;
967 foreach ($operation->det->array as $item) {
968 if ($operation->det->currency_id != 0) {
969 $array['amount'. $idx] = $item['oc_amount'];
970 $idx++;
971 }
972 }
973
974 }elseif ( $operation->signature==="ACH" || $operation->signature=="VEN") {
975 $idx=0;
976 foreach ($operation->det->array as $item) {
977
978 // currency replace amount
979 if ($operation->det->currency_id != 0 ) {
980 $array['e_march'.$idx.'_tva_amount']=$item['oc_vat_amount'];
981 $array['e_march'.$idx.'_tva_amount']=$item['oc_amount'];
982 $array['e_march'.$idx.'_price']=$item['oc_price_unit'];
983 }
984
985 if ( isset ($item['qs_vat_sided']) && $item['qs_vat_sided'] != 0 ) {
986 $array['e_march'.$idx.'_tva_amount']=0;
987 }elseif (isset ($item['qp_vat_sided']) && $item['qp_vat_sided'] != 0 ){
988 $array['e_march'.$idx.'_tva_amount']=0;
989 }
990
991 $idx++;
992 }
993 }elseif ($operation->signature=='FIN') {
994 $idx=0;
995 foreach ($operation->det->array as $item) {
996 if ($operation->det->currency_id != 0) {
997 $array['e_other' . $idx . '_amount'] = $item['oc_amount'];
998 $idx++;
999 }
1000 }
1001 }
1002
1003 if ( DEBUGNOALYSS>1) {
1004 echo \Noalyss\Dbg::hidden_info("operation->det_array", $operation->det->array);
1005 echo \Noalyss\Dbg::hidden_info("operation->det", $operation->det);
1006 echo \Noalyss\Dbg::hidden_info("array", $array);
1007 }
1008 // transform the operation into hidden element
1010 $r.=HtmlInput::hidden("e_comm",$operation->det->jr_comment);
1011 $r.=HtmlInput::submit(uniqid(), _("Dupliquer"));
1012 $r.=HtmlInput::button_close("duplicate_operation_div");
1013 $r.='</form>';
1014
1015
1016 // return the form as a string
1017 return $r;
1018 }
nbm($p_number, $p_dec=2)
format the number with a sep.
_("actif, passif,charge,...")
get_quant()
retrieve data from the table QUANT_*
static hidden()
return a string to set gDossier into a FORM
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static hidden($p_name, $p_value, $p_id="")
static simple_array_to_hidden($array)
Transform a double array as a HTML string with hidden html value array has the formarray ["name"]="x"...
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
if( $delta< 0) elseif( $delta==0)

References $array, $currency, $default_currency, $g_user, $i, $idx, $nb_array, $operation, $p_id, $r, $select, _, db, elseif, get_quant(), and nbm().

+ Here is the call graph for this function:

◆ get()

Acc_Operation::get ( )

retrieve data from jrnx and jrn

Returns
return an object
Note
See also

Reimplemented in Acc_Detail, Acc_Fin, Acc_Misc, Acc_Purchase, and Acc_Sold.

Definition at line 650 of file acc_operation.class.php.

651 {
652 $ret=new Acc_Misc($this->db,$this->jr_id);
653 $ret->get();
654 return $ret;
655 }

References $ret, db, and jr_id.

◆ get_amount()

Acc_Operation::get_amount ( )

return amount of the jr_id

Definition at line 849 of file acc_operation.class.php.

850 {
851 if ( $this->jr_id == 0 )
852 throw new Exception(_('Object invalide, id incorrect'));
853 $amount=$this->db->get_value('select jr_montant from jrn where jr_id=$1',
854 array($this->jr_id));
855 return $amount;
856 }

References $amount, _, db, and jr_id.

◆ get_currency_amount()

Acc_Operation::get_currency_amount ( )

retrieve amount in currency for the operation

Returns
amount in currency or 0 if this operation doesn't use currency
See also
Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc

Definition at line 700 of file acc_operation.class.php.

701 {
702 if ( $this->det->currency_id == 0 ) {
703 return 0;
704 }
705 $ledger_id=$this->get_ledger();
706 if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
707 $oledger=new Acc_Ledger($this->db,$ledger_id);
708
709 // retrieve info from jrn_info
710
711
712 switch($oledger->get_type())
713 {
714 case 'VEN':
715 $sql_amount="
716 select
717 sum(oc_amount)+sum(oc_vat_amount )
718 from operation_currency oc
719 join quant_sold qs using(j_id)
720 where
721 oc.j_id in (select j_id
722 from jrnx join jrn on (jr_grpt_id=j_grpt)
723 where jr_id=$1);
724 ";
725 break;
726 case 'ACH':
727 $sql_amount="
728 select
729 sum(oc_amount)+sum(oc_vat_amount )
730 from operation_currency oc
731 join quant_purchase qs using(j_id)
732 where
733 oc.j_id in (select j_id
734 from jrnx join jrn on (jr_grpt_id=j_grpt)
735 where jr_id=$1);
736 ";
737 break;
738 case 'FIN':
739 $sql_amount="
740 select
741 sum(oc_amount)+sum(oc_vat_amount )
742 from operation_currency oc
743 join quant_fin qs using(j_id)
744 where
745 oc.j_id in (select j_id
746 from jrnx join jrn on (jr_grpt_id=j_grpt)
747 where jr_id=$1);
748 ";
749 break;
750 default:
751 $sql_amount="
752 select
753 sum(oc_amount)+sum(oc_vat_amount )
754 from operation_currency oc
755 join jrnx using(j_id)
756 join jrn on (jr_grpt_id=j_grpt)
757 where
758 jr_id=$1 and j_debit='t';
759 ";
760 break;
761 }
762 $amount=$this->db->get_value($sql_amount,[$this->jr_id]);
763 return $amount;
764 }
if(isNumber($jr_id)==0) $ledger_id
get_ledger()
return the jrn_def_id from jrn

References $amount, $ledger_id, _, db, get_ledger(), and jr_id.

+ Here is the call graph for this function:

◆ get_data()

Acc_Operation::get_data ( $p_grpt)

Get data from jrnx where p_grpt=jrnx(j_grpt)

Parameters
connection
Returns
array of 3 elements
  • First Element is an array
    Array
    (
        [op_date] => 01.12.2009
        [class_cred0] => 7000008
        [mont_cred0] => 8880.0000
        [op_cred0] => 754
        [text_cred0] =>
        [jr_internal] => 23VEN-01-302
        [comment] =>
        [ech] =>
        [jr_id] => 302
        [jr_def_id] => 2
        [class_deb0] => 4000005
        [mont_deb0] => 10744.8000
        [text_deb0] =>
        [op_deb0] => 755
        [class_cred1] => 4511
        [mont_cred1] => 1864.8000
        [op_cred1] => 756
        [text_cred1] =>
    )
    
  • Second : number of line with debit
  • Third : number of line with credit

Definition at line 581 of file acc_operation.class.php.

582 {
583 $Res=$this->db->exec_sql("select
584 to_char(j_date,'DD.MM.YYYY') as j_date,
585 j_text,
586 j_debit,
587 j_poste,
588 coalesce(j_qcode,'-') as qcode,
589 j_montant,
590 j_id,
591 jr_comment,
592 to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
593 to_char(jr_date,'DD.MM.YYYY') as jr_date,
594 jr_id,jr_internal,jr_def_id,jr_pj
595 from jrnx inner join jrn on j_grpt=jr_grpt_id where j_grpt=$1",array($p_grpt));
596 $MaxLine=Database::num_row($Res);
597 if ( $MaxLine == 0 ) return null;
598 $deb=0;
599 $cred=0;
600 for ( $i=0; $i < $MaxLine; $i++)
601 {
602
604 $l_array['op_date']=$l_line['j_date'];
605 if ( $l_line['j_debit'] == 't' )
606 {
607 $l_class=sprintf("class_deb%d",$deb);
608 $l_montant=sprintf("mont_deb%d",$deb);
609 $l_text=sprintf("text_deb%d",$deb);
610 $l_qcode=sprintf("qcode_deb%d",$deb);
611 $l_array[$l_class]=$l_line['j_poste'];
612 $l_array[$l_montant]=$l_line['j_montant'];
613 $l_array[$l_text]=$l_line['j_text'];
614 $l_array[$l_qcode]=$l_line['qcode'];
615 $l_id=sprintf("op_deb%d",$deb);
616 $l_array[$l_id]=$l_line['j_id'];
617 $deb++;
618 }
619 if ( $l_line['j_debit'] == 'f' )
620 {
621 $l_class=sprintf("class_cred%d",$cred);
622 $l_montant=sprintf("mont_cred%d",$cred);
623 $l_array[$l_class]=$l_line['j_poste'];
624 $l_array[$l_montant]=$l_line['j_montant'];
625 $l_id=sprintf("op_cred%d",$cred);
626 $l_array[$l_id]=$l_line['j_id'];
627 $l_text=sprintf("text_cred%d",$cred);
628 $l_array[$l_text]=$l_line['j_text'];
629 $l_qcode=sprintf("qcode_cred%d",$cred);
630 $l_array[$l_qcode]=$l_line['qcode'];
631 $cred++;
632 }
633 $l_array['jr_internal']=$l_line['jr_internal'];
634 $l_array['comment']=$l_line['jr_comment'];
635 $l_array['ech']=$l_line['jr_ech'];
636 $l_array['jr_id']=$l_line['jr_id'];
637 $l_array['jr_def_id']=$l_line['jr_def_id'];
638 }
639 return array($l_array,$deb,$cred);
640 }
for($i=0;$i< $nb_jrn;$i++) $deb

References $cred, $deb, $i, $Res, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ get_info()

Acc_Operation::get_info ( )

retrieve info from the jrn_info, create 2 new arrays obj->info->command and obj->info->other the columns are the idx

Definition at line 770 of file acc_operation.class.php.

771 {
772 $this->info=new stdClass();
773 // other info
774 $array=$this->db->get_value("select ji_value from jrn_info where
775 jr_id=$1 and id_type=$2",array($this->jr_id,'OTHER'));
776 $this->info->other= $array;
777
778 // Bon de commande
779 $array=$this->db->get_value("select ji_value from jrn_info where
780 jr_id=$1 and id_type=$2",array($this->jr_id,'BON_COMMANDE'));
781 $this->info->command= $array;
782
783 }

References $array, db, and jr_id.

◆ get_internal()

Acc_Operation::get_internal ( )

Return the internal value, the property jr_id must be set before.

Returns
null si aucune valeur de trouv

Definition at line 393 of file acc_operation.class.php.

394 {
395 if ( ! isset($this->jr_id) )
396 throw new Exception('jr_id is not set',1);
397 $Res=$this->db->exec_sql("select jr_internal from jrn where jr_id=".$this->jr_id);
398 if ( Database::num_row($Res) == 0 ) return null;
400 $this->jr_internal= $l_line['jr_internal'];
401 return $this->jr_internal;
402 }

References $jr_internal, $Res, db, DatabaseCore\fetch_array(), jr_id, and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ get_jrnx_detail()

Acc_Operation::get_jrnx_detail ( )

retrieve data from jrnx

Note
the data are filtered by the access of the current user
Returns
an array or FALSE if nothing found

Definition at line 421 of file acc_operation.class.php.

422 {
423 global $g_user;
424 $filter_sql=$g_user->get_ledger_sql('ALL',3);
425 $filter_sql=noalyss_str_replace('jrn_def_id','jr_def_id',$filter_sql);
426 if ( $this->jr_id==0 ) return;
427 $sql=" select jr_id,j_id,jr_date,j_qcode,j_poste,j_montant,jr_internal,case when j_debit = 'f' then 'C' else 'D' end as debit,jr_comment as description,
428 vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter,jr_def_id ".
429 " from jrnx join jrn on (jr_grpt_id=j_grpt)
430 join tmp_pcmn on (j_poste=pcm_val)
431 left join vw_fiche_attr on (j_qcode=quick_code)
432 where
433 jr_id=$1 and $filter_sql order by j_debit desc";
434 $res=$this->db->exec_sql($sql,array($this->jr_id));
435 if ( Database::num_row ($res) == 0 ) return array();
437 return $all;
438 }
noalyss_str_replace($search, $replace, $string)
static fetch_all($ret)
wrapper for the function pg_fetch_all

References $all, $g_user, $res, $sql, db, DatabaseCore\fetch_all(), jr_id, noalyss_str_replace(), and DatabaseCore\num_row().

Referenced by display_jrnx_detail().

+ Here is the call graph for this function:

◆ get_ledger()

Acc_Operation::get_ledger ( )

return the jrn_def_id from jrn

Definition at line 462 of file acc_operation.class.php.

463 {
464 $sql="select jr_def_id from jrn where jr_id=$1";
465 $row=$this->db->get_value($sql,array($this->jr_id));
466 return $row;
467 }

References $row, $sql, db, and jr_id.

Referenced by get_currency_amount(), and get_quant().

◆ get_quant()

Acc_Operation::get_quant ( )

retrieve data from the table QUANT_*

Returns
return an object or null if there is no data from the QUANT table
See also
Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc

Definition at line 662 of file acc_operation.class.php.

663 {
664 $ledger_id=$this->get_ledger();
665 if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
666 $oledger=new Acc_Ledger($this->db,$ledger_id);
667
668 // retrieve info from jrn_info
669
670
671 switch($oledger->get_type())
672 {
673 case 'VEN':
674 $ret=new Acc_Sold($this->db,$this->jr_id);
675 break;
676 case 'ACH':
677 $ret=new Acc_Purchase($this->db,$this->jr_id);
678 break;
679 case 'FIN':
680 $ret=new Acc_Fin($this->db,$this->jr_id);
681 break;
682 default:
683 $ret=new Acc_Misc($this->db,$this->jr_id);
684 break;
685 }
686 $ret->get();
687 if ( empty($ret->det->array))
688 {
689 $ret=new Acc_Misc($this->db,$this->jr_id);
690 $ret->get();
691 }
692 $ret->get_info();
693 return $ret;
694 }

References $ledger_id, $ret, _, db, get_ledger(), and jr_id.

Referenced by form_clone_operation().

+ Here is the call graph for this function:

◆ get_sum_other_tax()

Acc_Operation::get_sum_other_tax ( )

get the sum of other tax linked to this operation

Definition at line 251 of file acc_operation.class.php.

251 {
252 if ( $this->jr_id == 0 ) {return 0;}
253 $sum=$this->db->get_value("select
254 sum(case when j_debit is false and jrn_def.jrn_def_type='ACH'
255 then 0-j_montant when j_debit is true and jrn_def.jrn_def_type='VEN'
256 then 0-j_montant
257 else j_montant end) sum_tax
258 from
259 jrn_tax join jrnx j1 using (j_id)
260 join jrn on (jr_grpt_id=j1.j_grpt)
261 join jrn_def on (jrn.jr_def_id=jrn_def.jrn_def_id)
262 where
263 jrn.jr_id=$1",[$this->jr_id]);
264 ;
265 if ( $this->db->count()==0) {return 0;}
266 return $sum;
267 }

References db, and jr_id.

◆ insert_jrn()

Acc_Operation::insert_jrn ( )

Insert into the table Jrn, the amount is computed from jrnx thanks the group id ($p_grpt)

Returns
sequence of jr_id

Definition at line 349 of file acc_operation.class.php.

350 {
351 $p_comment=$this->desc;
352 if ( DEBUGNOALYSS > 1 ) {
353 echo "insert_jrn = {$this->amount} <br>";
354 }
355 $diff=$this->db->get_value("select check_balance ($1)",array($this->grpt));
356 if ( $diff != 0 )
357 {
358
359 printf (_("Erreur : balance incorrecte :diff = %s"),$diff);
360 return false;
361 }
362
363 $echeance=( isset( $this->echeance) && noalyss_strlentrim($this->echeance) != 0)?$this->echeance:null;
364 if ( ! isset($this->mt) )
365 {
366 $this->mt=microtime(true);
367 }
368
369 // if amount == -1then the triggers will throw an error
370 //
371 $this->amount=(trim($this->amount)==''||$this->amount==NULL)?0:$this->amount;
372 $Res=$this->db->exec_sql("insert into jrn (jr_def_id,jr_montant,jr_comment,".
373 "jr_date,jr_ech,jr_grpt_id,jr_tech_per,jr_mt,jr_optype,currency_id,currency_rate,currency_rate_ref) values (".
374 "$1,$2,$3,".
375 "to_date($4,'DD.MM.YYYY'),to_date($5,'DD.MM.YYYY'),$6,$7,$8,$9,$10,$11,$12)",
376 array ($this->jrn, $this->amount,$p_comment,
377 $this->date,$echeance,$this->grpt,$this->periode,$this->mt,$this->jr_optype,
378 $this->currency_id,$this->currency_rate,$this->currency_rate_ref)
379 );
380 if ($Res==FALSE)
381 {
382 return FALSE;
383 }
384 $this->jr_id=$this->db->get_current_seq('s_jrn');
385 return $this->jr_id;
386 }
$bal jrn

References $amount, $desc, $diff, $echeance, $jr_id, $Res, _, db, jr_id, jrn, and noalyss_strlentrim().

+ Here is the call graph for this function:

◆ insert_jrnx()

Acc_Operation::insert_jrnx ( )

Insert into the table Jrn The needed data are :

  • this->date
  • this->amount
  • this->poste
  • this->grpt
  • this->jrn
  • this->type ( debit or credit)
  • this->user
  • this->periode
  • this->qcode
  • this->desc optional
    Note
    if the amount is less than 0 then side changes, for example debit becomes a credit and vice versa
    Returns
    jrnx.j_id

Definition at line 214 of file acc_operation.class.php.

215 {
216 if ( $this->poste == "") { throw new Exception (__FILE__.':'.__LINE__.' Poste comptable vide');return false; }
217 /* for negative amount the operation is reversed */
218 if ( $this->amount < 0 )
219 {
220 $this->type=($this->type=='d')?'c':'d';
221 }
222 if ( DEBUGNOALYSS > 1 ) {
223 echo "insert_jrnx = [{ $this->poste}] {$this->amount} rounded ".round($this->amount,2)." type {$this->type}<br>";
224 }
225 $this->amount=abs($this->amount);
226 $debit=($this->type=='c')?'false':'true';
227 $this->desc=(isset($this->desc))?$this->desc:'';
228 $this->amount=(trim($this->amount)==''||$this->amount==NULL)?0:$this->amount;
229 $Res=$this->db->exec_sql("select insert_jrnx
230 ($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
231 array(
232 $this->date, //$1
233 round($this->amount,2), //$2
234 $this->poste, //$3
235 $this->grpt, //$4
236 $this->jrn, //$5
237 $debit, //$6
238 $this->user, //$7
239 $this->periode, //$8
240 $this->qcode, // $9
241 $this->desc)); //$10
242 if ( $Res===FALSE) return FALSE;
243 $this->jrnx_id=$this->db->get_current_seq('s_jrn_op');
244 return $this->jrnx_id;
245
246 }
$input_from type

References $amount, $debit, $jrnx_id, $Res, db, jrn, type, and user.

Referenced by Acc_Ledger_Purchase\insert_no_deductible().

◆ insert_related_action()

Acc_Operation::insert_related_action ( $p_string)

Definition at line 808 of file acc_operation.class.php.

809 {
810 if ($p_string == "") return;
811 $a_action=explode(',',$p_string);
812 for ($i=0;$i<count($a_action);$i++)
813 {
814 $action = new Follow_Up($this->db,$a_action[$i]);
815 $action->operation=$this->jr_id;
816 $action->insert_operation();
817 }
818 }

References $action, $i, $jr_id, and db.

◆ operation_update_comment()

Acc_Operation::operation_update_comment ( $p_text)

add a comment to the operation (jrn.jr_text)

Definition at line 446 of file acc_operation.class.php.

447 {
448 $sql="update jrn set jr_comment=$1 where jr_id=$2";
449 $this->db->exec_sql($sql,array($p_text,$this->jr_id));
450 }

References $sql, db, and jr_id.

◆ operation_update_date_limit()

Acc_Operation::operation_update_date_limit ( $p_text)

add a limit of payment to the operation (jrn.jr_ech)

Definition at line 452 of file acc_operation.class.php.

453 {
454 if ( isDate($p_text) == null )
455 {
456 $p_text=null;
457 }
458 $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
459 $this->db->exec_sql($sql,array($p_text,$this->jr_id));
460 }
isDate($p_date)

References $sql, db, isDate(), and jr_id.

+ Here is the call graph for this function:

◆ prepare_sql_counterpart()

Acc_Operation::prepare_sql_counterpart ( )
private

prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn.jr_id , jrnx.j_id) must be provided

Definition at line 141 of file acc_operation.class.php.

142 {
143 // prepare for getting the tiers
144 $this->db->prepare('prep_counterpart',"select fiche_detail.f_id,ad_value from
145 fiche_detail
146 join (select qf_bank as f_id
147 from quant_fin
148 where
149 quant_fin.jr_id = $1
150 union all
151 select qp_fiche as f_id
152 from quant_purchase
153 where quant_purchase.j_id=$2
154 union all
155 select qs_fiche as f_id
156 from quant_sold
157 where quant_sold.j_id=$2 ) as v_fiche on (fiche_detail.f_id=v_fiche.f_id) where ad_id=23 ");
158 }

References db.

Referenced by find_tiers().

◆ prepare_sql_tiers()

Acc_Operation::prepare_sql_tiers ( )
private

prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn.jr_id , jrnx.j_id) must be provided

Definition at line 118 of file acc_operation.class.php.

119 {
120 // prepare for getting the tiers
121 $this->db->prepare('prep_tiers',"select fiche_detail.f_id,ad_value from
122 fiche_detail
123 join (select qf_other as f_id
124 from quant_fin
125 where
126 quant_fin.jr_id = $1
127 union all
128 select qp_supplier as f_id
129 from quant_purchase
130 where quant_purchase.j_id=$2
131 union all
132 select qs_client as f_id
133 from quant_sold
134 where quant_sold.j_id=$2 ) as v_fiche on (fiche_detail.f_id=v_fiche.f_id) where ad_id=23 ");
135 }

References db.

Referenced by find_tiers().

◆ save_info()

Acc_Operation::save_info ( $p_info,
$p_type )

Save into jrn_info.

Parameters
$p_infomsg to save
$p_typeis OTHER or BON_COMMAND

Definition at line 789 of file acc_operation.class.php.

790 {
791 if ( ! in_array($p_type,array('OTHER','BON_COMMANDE'))) return;
792 if (trim($p_info)=="") {
793 $this->db->exec_sql('delete from jrn_info where jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
794 return;
795 }
796 $exist=$this->db->get_value('select count(ji_id) from jrn_info where jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
797 if ( $exist == "0" ) {
798 //insert into jrn_info
799 $this->db->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)',
800 array($this->jr_id,$p_type,$p_info));
801 } elseif ( $exist == 1) {
802 //update
803 $this->db->exec_sql('update jrn_info set ji_value=$3 where jr_id=$1 and id_type=$2',
804 array($this->jr_id,$p_type,$p_info));
805 }
806 }

References $p_type, db, elseif, and jr_id.

◆ seek_group()

Acc_Operation::seek_group ( )

retrieve the grpt_id from jrn for a jr_id

Returns
jrn.jr_grpt_id or an empty string if not found

Definition at line 107 of file acc_operation.class.php.

108 {
109 $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
110 array($this->jr_id));
111 return $ret;
112 }

References $ret, db, and jr_id.

◆ seek_internal()

Acc_Operation::seek_internal ( $p_internal)

search an operation thankx it internal code

Parameters
internalcode
Returns
0 ok -1 nok

Definition at line 408 of file acc_operation.class.php.

409 {
410 $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
411 array($p_internal));
412 if ( Database::num_row($res) == 0 ) return -1;
414 return 0;
415 }
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all

References $res, db, DatabaseCore\fetch_result(), jr_id, and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ select_operation_type()

static Acc_Operation::select_operation_type ( $p_status)
static

Return a select object to choose the type of operation.

  • NOR normal
  • EXT reverse operation
  • CLO closing periode
  • OPE opening periode
    Parameters
    string$p_status
    Returns
    \ISelect

Definition at line 879 of file acc_operation.class.php.

880 {
881 $type_operation=new ISelect("jr_optype");
882 $type_operation->value=array(
883 array(("label")=>_("Normal"), "value"=>"NOR"),
884 array(("label")=>_("Ouverture"), "value"=>"OPE"),
885 array(("label")=>_("Fermeture"), "value"=>"CLO"),
886 array(("label")=>_("Extourne"), "value"=>"EXT")
887 );
888
889 $type_operation->selected=$p_status;
890 return $type_operation;
891 }

References _.

◆ set_id()

Acc_Operation::set_id ( $p_id)

set the operation id (jrn.jr_id)

Parameters
type$p_id

Definition at line 823 of file acc_operation.class.php.

824 {
825 if (isNumber($p_id)==0) {
826 throw new Exception(_('Acc_Operation::set_id , id invalide '));
827 }
828 $this->jr_id=$p_id;
829 }
isNumber($p_int)

References $p_id, _, isNumber(), and jr_id.

+ Here is the call graph for this function:

◆ set_paid()

Acc_Operation::set_paid ( )

flag the operation as paid

Definition at line 833 of file acc_operation.class.php.

834 {
835 // Operation
836 if ( $this->jr_id == 0 )
837 throw new Exception(_('Object invalide, id incorrect'));
838 if (
839 $this->db->get_value('select count(*) from jrn where jr_id=$1',
840 array($this->jr_id)) == 0 )
841 throw new Exception(_('Object invalide, id incorrect'));
842
843 $this->db->exec_sql("update jrn set jr_rapt = 'paid' where jr_id = $1",
844 array($this->jr_id));
845 }

References _, db, and jr_id.

◆ test_me()

static Acc_Operation::test_me ( )
static

Definition at line 857 of file acc_operation.class.php.

858 {
859 global $g_user;
861 $g_user=new Noalyss_user($cn);
862 $a=new Acc_Operation($cn);
863 $a->jr_id=993;
864 $b=$a->get_quant();
865 echo h1('contain of get_quant() ');
866 var_dump($b);
867 echo h1('contain of get_jrnx_detail()');
868 var_dump($a->get_jrnx_detail());
869 }
h1($p_string, $p_class="")
Definition ac_common.php:72
static connect()

References $a, $b, $cn, $g_user, and h1().

+ Here is the call graph for this function:

◆ update_comment()

Acc_Operation::update_comment ( $p_text)

add a comment to the line (jrnx.j_text)

Definition at line 440 of file acc_operation.class.php.

441 {
442 $sql="update jrnx set j_text=$1 where j_id=$2";
443 $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
444 }

References $sql, and db.

◆ update_receipt()

Acc_Operation::update_receipt ( )

set the pj of a operation in jrn. the jr_id must be set

Note
if the jr_id it fails

Definition at line 273 of file acc_operation.class.php.

274 {
275 if ( noalyss_strlentrim($this->pj) == 0 )
276 {
277 // echo __LINE__."debug {$this->pj} est vide";
278 $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
279 $this->db->exec_sql($sql,array(null,$this->jr_id));
280 return '';
281 }
282 /* is pj uniq ? */
283 if ( $this->db->count_sql("select jr_id from jrn
284 where jr_pj_number=$1 and jr_def_id=$2
285 and jr_id !=$3",
286 array($this->pj,$this->jrn,$this->jr_id)
287 ) == 0 )
288 {
289
290 $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
291 $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
292 }
293 else
294 {
295 /* get pref */
296 $pref=$this->db->get_value("select jrn_def_pj_pref from jrn_def where jrn_def_id=$1",
297 array($this->jrn));
298 /* try another seq */
299 $flag=0;
300 $limit=100;
301 while ( $flag == 0 )
302 {
303 /* limit the search to $limit */
304 if ( $limit < 1 )
305 {
306 $this->pj='';
307 $flag=2;
308 break;
309 }
310 /* get padding */
311 $padding=$this->db->get_value("select jrn_def_pj_padding from jrn_def where jrn_def_id=$1",
312 array($this->jrn));
313
314 $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn);
315
316 // see Acc_Ledger::guess_pj
317 $this->pj=$pref.str_pad($seq,$padding??0,'0',STR_PAD_LEFT);
318
319 /* check if the new pj numb exist */
320 $c=$this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2
321 and jr_id !=$3",
322 array($this->pj,$this->jrn,$this->jr_id)
323 );
324 if ( $c == 0 )
325 {
326 $flag=1;
327 break;
328 }
329 $limit--;
330 }
331 /* a pj numb is found */
332 if ( $flag == 1 )
333 {
334 $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
335 $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
336 }
337 }
338 return $this->pj;
339 }
$c
Definition compute.php:48
$flag
Definition install.php:536

References $c, $flag, $limit, $pj, $seq, $sql, db, jr_id, jrn, and noalyss_strlentrim().

+ Here is the call graph for this function:

Field Documentation

◆ $amount

Acc_Operation::$amount

amount of the operatoin

Definition at line 44 of file acc_operation.class.php.

Referenced by get_amount(), get_currency_amount(), insert_jrn(), and insert_jrnx().

◆ $currency_id

Acc_Operation::$currency_id

Definition at line 49 of file acc_operation.class.php.

◆ $currency_rate

Acc_Operation::$currency_rate

Definition at line 48 of file acc_operation.class.php.

◆ $currency_rate_ref

Acc_Operation::$currency_rate_ref

Definition at line 50 of file acc_operation.class.php.

◆ $date

Acc_Operation::$date

the date

Definition at line 42 of file acc_operation.class.php.

◆ $date_paid

Acc_Operation::$date_paid

Definition at line 46 of file acc_operation.class.php.

◆ $db

Acc_Operation::$db

database connx

Definition at line 35 of file acc_operation.class.php.

◆ $debit

Acc_Operation::$debit

debit or credit

Definition at line 38 of file acc_operation.class.php.

Referenced by insert_jrnx().

◆ $desc

Acc_Operation::$desc

Definition at line 56 of file acc_operation.class.php.

Referenced by insert_jrn().

◆ $echeance

Acc_Operation::$echeance

Definition at line 59 of file acc_operation.class.php.

Referenced by insert_jrn().

◆ $f_id

Acc_Operation::$f_id

Definition at line 62 of file acc_operation.class.php.

◆ $grpt

Acc_Operation::$grpt

the group id

Definition at line 45 of file acc_operation.class.php.

◆ $jr_id

Acc_Operation::$jr_id

pk of jrn

Definition at line 36 of file acc_operation.class.php.

Referenced by insert_jrn(), and insert_related_action().

◆ $jr_internal

Acc_Operation::$jr_internal

Definition at line 54 of file acc_operation.class.php.

Referenced by get_internal().

◆ $jr_optype

Acc_Operation::$jr_optype

type of operation :NOR,CLO,EXT,OPE

Definition at line 47 of file acc_operation.class.php.

◆ $jrn

Acc_Operation::$jrn

the ledger to use

Definition at line 40 of file acc_operation.class.php.

◆ $jrn_id

Acc_Operation::$jrn_id

jrn_def_id

Definition at line 37 of file acc_operation.class.php.

◆ $jrnx_id

Acc_Operation::$jrnx_id

Definition at line 58 of file acc_operation.class.php.

Referenced by insert_jrnx().

◆ $mt

Acc_Operation::$mt

Definition at line 61 of file acc_operation.class.php.

◆ $periode

Acc_Operation::$periode

periode to use

Definition at line 43 of file acc_operation.class.php.

◆ $pj

Acc_Operation::$pj

Definition at line 60 of file acc_operation.class.php.

Referenced by update_receipt().

◆ $poste

Acc_Operation::$poste

account

Definition at line 41 of file acc_operation.class.php.

◆ $qcode

Acc_Operation::$qcode

< Qcode of item

internal code from jrn

Definition at line 52 of file acc_operation.class.php.

◆ $signature

Acc_Operation::$signature

Definition at line 55 of file acc_operation.class.php.

◆ $type

Acc_Operation::$type

Definition at line 57 of file acc_operation.class.php.

◆ $user

Acc_Operation::$user

current user

Definition at line 39 of file acc_operation.class.php.


The documentation for this class was generated from the following file: