noalyss Version-9
Public Member Functions | Static Public Member Functions | Data Fields | Private Member Functions
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 More...
 
 __toString ()
 
 display_jrnx_detail ($p_table)
 display_jrnx_detail : get the data from get_jrnx_data and return a string with HTML code More...
 
 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. More...
 
 form_clone_operation ($p_id)
 create a form to recreate the operation and returns it, just like a correct More...
 
 get ()
 retrieve data from jrnx and jrn More...
 
 get_amount ()
 return amount of the jr_id More...
 
 get_currency_amount ()
 retrieve amount in currency for the operation More...
 
 get_data ($p_grpt)
 Get data from jrnx where p_grpt=jrnx(j_grpt) More...
 
 get_info ()
 retrieve info from the jrn_info, create 2 new arrays obj->info->command and obj->info->other the columns are the idx More...
 
 get_internal ()
 Return the internal value, the property jr_id must be set before. More...
 
 get_jrnx_detail ()
 retrieve data from jrnx More...
 
 get_ledger ()
 return the jrn_def_id from jrn More...
 
 get_quant ()
 retrieve data from the table QUANT_* More...
 
 get_sum_other_tax ()
 get the sum of other tax linked to this operation More...
 
 insert_jrn ()
 Insert into the table Jrn, the amount is computed from jrnx thanks the group id ($p_grpt) More...
 
 insert_jrnx ()
 Insert into the table Jrn The needed data are : More...
 
 insert_related_action ($p_string)
 
 operation_update_comment ($p_text)
 add a comment to the operation (jrn.jr_text) More...
 
 operation_update_date_limit ($p_text)
 add a limit of payment to the operation (jrn.jr_ech) More...
 
 save_info ($p_info, $p_type)
 Save into jrn_info. More...
 
 seek_group ()
 retrieve the grpt_id from jrn for a jr_id More...
 
 seek_internal ($p_internal)
 search an operation thankx it internal code More...
 
 set_id ($p_id)
 set the operation id (jrn.jr_id) More...
 
 set_paid ()
 flag the operation as paid More...
 
 set_pj ()
 set the pj of a operation in jrn. the jr_id must be set More...
 
 update_comment ($p_text)
 add a comment to the line (jrnx.j_text) More...
 

Static Public Member Functions

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

Data Fields

 $amount
 
 $currency_id
 
 $currency_rate
 
 $currency_rate_ref
 
 $date
 
 $date_paid
 
 $db
 
 $debit
 
 $grpt
 
 $jr_id
 
 $jr_internal
 
 $jr_optype
 
 $jrn
 
 $jrn_id
 
 $periode
 
 $poste
 
 $qcode
 < Qcode of item More...
 
 $signature
 
 $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 More...
 
 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 More...
 

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 60 of file acc_operation.class.php.

61 {
62 global $g_user;
63 $this->db=$p_cn;
64 $this->qcode="";
65 $this->user=$_SESSION[SESSION_KEY.'g_user'];
66 $this->periode=$g_user->get_periode();
67 $this->jr_id=0;
68 $this->jr_optype="NOR";
69 $this->amount=0;
70 $this->currency_rate=1;
71 $this->currency_rate_ref=1;
72 $this->currency_id=NULL;
73 }
global $g_user
if no group available , then stop
$op jr_id
Definition: ajax_ledger.php:83
$input_from user
Definition: balance.inc.php:68
$SecUser db

References $g_user, db, jr_id, and user.

Member Function Documentation

◆ __toString()

Acc_Operation::__toString ( )

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

75 : string
76 {
77 $r=<<<EOF
78 Acc_Operation Object
79 [
80 db {$this->db}
81 qcode {$this->qcode}
82 user {$this->user}
83 periode {$this->periode}
84 jr_id {$this->jr_id}
85 jr_optype {$this->jr_optype}
86 amount {$this->amount}
87 currency_rate {$this->amount}
88 currency_rate_ref {$this->amount}
89 currency_id {$this->amount}
90 ]
91EOF;
92 return $r;
93
94 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...

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 458 of file acc_operation.class.php.

459 {
460 $show=$this->get_jrnx_detail();
461
462 $r='';
463 $r_notable='';
464 $csv="";
465 foreach ($show as $l)
466 {
467 $border="";
468 if ( $l['j_poste'] == $this->poste || ($l['j_qcode']==$this->qcode && trim($this->qcode) != ''))
469 $border=' class="highlight"';
470 $r.='<tr '.$border.'>';
471 $r.='<td>';
472 $a=$l['j_qcode'];
473
474 $r_notable.=$a;
475 $r.=$a;
476 $csv.='"'.$a.'";';
477 $r.='</td>';
478
479 $r.='<td '.$border.'>';
480 $a=$l['j_poste'];
481 $r_notable.=$a;
482 $r.=$a;
483 $csv.='"'.$a.'";';
484 $r.='</td>';
485
486 $r.='<td '.$border.'>';
487 // $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
488 $a=(noalyss_strlentrim($l['j_qcode'])==0)?$l['pcm_lib']:$l['vw_name'];
489 $r_notable.=$a;
490 $r.=h($a);
491 $csv.='"'.$a.'";';
492 $r.='</td>';
493
494 $r.='<td '.$border.'>';
495 $a=$l['j_montant'];
496 $r_notable.=$a;
497 $r.=$a;
498 $csv.=$a.';';
499 $r.='</td>';
500
501 $r.='<td '.$border.'>';
502 $a=$l['debit'];
503 $r_notable.=$a;
504 $r.=$a;
505 $csv.='"'.$a.'"';
506
507 $csv.="\r\n";
508 $r.='</td>';
509 $r.='<td '.$border.'>';
510 $a=($l['letter']!=-1)?$l['letter']:'';
511 $r_notable.=$a;
512 $r.=$a;
513 $csv.='"'.$a.'"';
514
515 $csv.="\r\n";
516 $r.='</td>';
517
518
519 $r.='</tr>';
520 }
521 switch ($p_table)
522 {
523 case 1:
524 return $r;
525 break;
526 case 0:
527 return $r_notable;
528 break;
529 case 2:
530 return $csv;
531 }
532 return "ERROR PARAMETRE";
533 }
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
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 160 of file acc_operation.class.php.

161 {
162 static $p=0;
163 if ( $p == 0 ){
165 $this->prepare_sql_tiers();
166 $p=1;
167 }
168 $tiers="";
169 $res_tiers=$this->db->execute('prep_tiers',
170 array($pn_jrn_id,$pn_jrnx_id));
171 if ( Database::num_row($res_tiers) > 0) {
172 $atiers=Database::fetch_array($res_tiers);
173 $tiers=$atiers['ad_value'];
174 // If the found tiers has the same quickcode than the current
175 // card, it means it is a card of supplier or customer,
176 // so we must look for the countercard
177 if ($tiers == $p_code) {
178 $res_counterpart=$this->db->execute('prep_counterpart',
179 array($pn_jrn_id,$pn_jrnx_id));
180 $tiers="";
181 if ( Database::num_row($res_counterpart) > 0) {
182 $atiers=Database::fetch_array($res_counterpart);
183 $tiers=$atiers['ad_value'];
184 }
185 }
186 }
187 return $tiers;
188 }
$p
Definition: array.php:34
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, just like a correct

Parameters
$p_idstring DOMID of the form

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

880 {
881 // retrieve all info about operation
882 $operation = $this->get_quant();
883 $array=$operation->compute_array();
884
885 global $g_user;
886 $a_code=$this->db->get_array("select code from v_menu_dependency vmd where me_code=$1 and p_id=$2",
887 array( $operation->signature,$g_user->get_profile()));
888 if ( empty ($a_code)) {
889 $r=_("Menu invalide");
890 return $r;
891 }
892
893 // Prepare the form
894 // select the menu where the operation will be duplicated
895 $r=sprintf('<form id="%s" method="POST" ACTION="%s">',$p_id,NOALYSS_URL."/do.php?".http_build_query([
896 "ac"=>$a_code[0]['code'],"gDossier"=>Dossier::id()
897 ]));
899 // select the menu where the operation will be duplicated
900 $r.="<p>";
901 $r.="<ul style=\"margin-left:2rem;padding-left:0;list-style:none;\">";
902 $r.=sprintf("<li>%s</li>",$operation->det->jr_pj_number);
903 $r.=sprintf("<li>%s</li>",$operation->det->jr_comment);
904 $r.=sprintf("<li>%s</li>",$operation->det->jr_montant);
905 $r.="</ul>";
906 $r.="</p>";
907 if (count($a_code) == 1 ) {
908 $r.=HtmlInput::hidden("ac",$a_code[0]['code']);
909 $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$a_code[0]['code']);
910
911 } else {
912 $select=new ISelect("ac");
913 $select->value=array();
914 $nb_code=count($a_code);
915
916 for ($i=0;$i<$nb_code;$i++) {
917 $select->value[]=array("label"=>$a_code[$i]['code'],"value"=>$a_code[$i]['code']);
918 }
919 $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$select->input());
920
921 }
922
923 $r.="</p>";
924
925 // For Misc Operation , if a card is given then there is no accounting
926 if ( $operation->signature==="ODS") {
927 $nb_array = count($array);
928 for ($i = 0; $i < $nb_array; $i++) {
929 if (isset ($array["qc_" . $i]) && $array["qc_" . $i] != "") {
930 $array["poste" . $i] = "";
931 }
932 }
933 }
934
935 if ( $operation->signature==="ACH" || $operation->signature=="VEN") {
936 $idx=0;
937 foreach ($operation->det->array as $item) {
938 if ( isset ($item['qs_vat_sided']) && $item['qs_vat_sided'] != 0 ) {
939 $array['e_march'.$idx.'_tva_amount']=0;
940 }elseif (isset ($item['qp_vat_sided']) && $item['qp_vat_sided'] != 0 ){
941 $array['e_march'.$idx.'_tva_amount']=0;
942 }
943 $idx++;
944 }
945 if ( DEBUGNOALYSS>1) {
946 echo \Noalyss\Dbg::hidden_info("operation->det_array", $operation->det->array);
947 echo \Noalyss\Dbg::hidden_info("array", $array);
948 }
949 }
950
951 // transform the operation into hidden element
953 $r.=HtmlInput::hidden("e_comm",$operation->det->jr_comment);
954 $r.=HtmlInput::submit(uniqid(), _("Dupliquer"));
955 $r.=HtmlInput::button_close("duplicate_operation_div");
956 $r.='</form>';
957
958
959 // return the form as a string
960 return $r;
961 }
$idx
get_quant()
retrieve data from the table QUANT_*
static id()
return the 'gDossier' value after a check
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")
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
if( $delta< 0) elseif( $delta==0)

References $array, $g_user, $i, $idx, $nb_array, $operation, $p_id, $r, $select, HtmlInput\button_close(), db, elseif, get_quant(), HtmlInput\hidden(), Dossier\hidden(), Dossier\id(), HtmlInput\simple_array_to_hidden(), and HtmlInput\submit().

+ 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_Misc, Acc_Sold, Acc_Purchase, and Acc_Fin.

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

636 {
637 $ret=new Acc_Misc($this->db,$this->jr_id);
638 $ret->get();
639 return $ret;
640 }
this class manage data from the JRNX and JRN table

References $ret, db, and jr_id.

◆ get_amount()

Acc_Operation::get_amount ( )

return amount of the jr_id

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

835 {
836 if ( $this->jr_id == 0 )
837 throw new Exception(_('Object invalide, id incorrect'));
838 $amount=$this->db->get_value('select jr_montant from jrn where jr_id=$1',
839 array($this->jr_id));
840 return $amount;
841 }

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 685 of file acc_operation.class.php.

686 {
687 if ( $this->det->currency_id == 0 ) {
688 return 0;
689 }
690 $ledger_id=$this->get_ledger();
691 if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
692 $oledger=new Acc_Ledger($this->db,$ledger_id);
693
694 // retrieve info from jrn_info
695
696
697 switch($oledger->get_type())
698 {
699 case 'VEN':
700 $sql_amount="
701 select
702 sum(oc_amount)+sum(oc_vat_amount )
703 from operation_currency oc
704 join quant_sold qs using(j_id)
705 where
706 oc.j_id in (select j_id
707 from jrnx join jrn on (jr_grpt_id=j_grpt)
708 where jr_id=$1);
709 ";
710 break;
711 case 'ACH':
712 $sql_amount="
713 select
714 sum(oc_amount)+sum(oc_vat_amount )
715 from operation_currency oc
716 join quant_purchase qs using(j_id)
717 where
718 oc.j_id in (select j_id
719 from jrnx join jrn on (jr_grpt_id=j_grpt)
720 where jr_id=$1);
721 ";
722 break;
723 case 'FIN':
724 $sql_amount="
725 select
726 sum(oc_amount)+sum(oc_vat_amount )
727 from operation_currency oc
728 join quant_fin qs using(j_id)
729 where
730 oc.j_id in (select j_id
731 from jrnx join jrn on (jr_grpt_id=j_grpt)
732 where jr_id=$1);
733 ";
734 break;
735 default:
736 $sql_amount="
737 select
738 sum(oc_amount)+sum(oc_vat_amount )
739 from operation_currency oc
740 join jrnx using(j_id)
741 join jrn on (jr_grpt_id=j_grpt)
742 where
743 jr_id=$1 and j_debit='t';
744 ";
745 break;
746 }
747 $amount=$this->db->get_value($sql_amount,[$this->jr_id]);
748 return $amount;
749 }
$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 566 of file acc_operation.class.php.

567 {
568 $Res=$this->db->exec_sql("select
569 to_char(j_date,'DD.MM.YYYY') as j_date,
570 j_text,
571 j_debit,
572 j_poste,
573 coalesce(j_qcode,'-') as qcode,
574 j_montant,
575 j_id,
576 jr_comment,
577 to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
578 to_char(jr_date,'DD.MM.YYYY') as jr_date,
579 jr_id,jr_internal,jr_def_id,jr_pj
580 from jrnx inner join jrn on j_grpt=jr_grpt_id where j_grpt=$1",array($p_grpt));
581 $MaxLine=Database::num_row($Res);
582 if ( $MaxLine == 0 ) return null;
583 $deb=0;
584 $cred=0;
585 for ( $i=0; $i < $MaxLine; $i++)
586 {
587
589 $l_array['op_date']=$l_line['j_date'];
590 if ( $l_line['j_debit'] == 't' )
591 {
592 $l_class=sprintf("class_deb%d",$deb);
593 $l_montant=sprintf("mont_deb%d",$deb);
594 $l_text=sprintf("text_deb%d",$deb);
595 $l_qcode=sprintf("qcode_deb%d",$deb);
596 $l_array[$l_class]=$l_line['j_poste'];
597 $l_array[$l_montant]=$l_line['j_montant'];
598 $l_array[$l_text]=$l_line['j_text'];
599 $l_array[$l_qcode]=$l_line['qcode'];
600 $l_id=sprintf("op_deb%d",$deb);
601 $l_array[$l_id]=$l_line['j_id'];
602 $deb++;
603 }
604 if ( $l_line['j_debit'] == 'f' )
605 {
606 $l_class=sprintf("class_cred%d",$cred);
607 $l_montant=sprintf("mont_cred%d",$cred);
608 $l_array[$l_class]=$l_line['j_poste'];
609 $l_array[$l_montant]=$l_line['j_montant'];
610 $l_id=sprintf("op_cred%d",$cred);
611 $l_array[$l_id]=$l_line['j_id'];
612 $l_text=sprintf("text_cred%d",$cred);
613 $l_array[$l_text]=$l_line['j_text'];
614 $l_qcode=sprintf("qcode_cred%d",$cred);
615 $l_array[$l_qcode]=$l_line['qcode'];
616 $cred++;
617 }
618 $l_array['jr_internal']=$l_line['jr_internal'];
619 $l_array['comment']=$l_line['jr_comment'];
620 $l_array['ech']=$l_line['jr_ech'];
621 $l_array['jr_id']=$l_line['jr_id'];
622 $l_array['jr_def_id']=$l_line['jr_def_id'];
623 }
624 return array($l_array,$deb,$cred);
625 }
$Res
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 755 of file acc_operation.class.php.

756 {
757 $this->info=new stdClass();
758 // other info
759 $array=$this->db->get_value("select ji_value from jrn_info where
760 jr_id=$1 and id_type=$2",array($this->jr_id,'OTHER'));
761 $this->info->other= $array;
762
763 // Bon de commande
764 $array=$this->db->get_value("select ji_value from jrn_info where
765 jr_id=$1 and id_type=$2",array($this->jr_id,'BON_COMMANDE'));
766 $this->info->command= $array;
767
768 }

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 380 of file acc_operation.class.php.

381 {
382 if ( ! isset($this->jr_id) )
383 throw new Exception('jr_id is not set',1);
384 $Res=$this->db->exec_sql("select jr_internal from jrn where jr_id=".$this->jr_id);
385 if ( Database::num_row($Res) == 0 ) return null;
387 $this->jr_internal= $l_line['jr_internal'];
388 return $this->jr_internal;
389 }

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 406 of file acc_operation.class.php.

407 {
408 global $g_user;
409 $filter_sql=$g_user->get_ledger_sql('ALL',3);
410 $filter_sql=noalyss_str_replace('jrn_def_id','jr_def_id',$filter_sql);
411 if ( $this->jr_id==0 ) return;
412 $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,
413 vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter,jr_def_id ".
414 " from jrnx join jrn on (jr_grpt_id=j_grpt)
415 join tmp_pcmn on (j_poste=pcm_val)
416 left join vw_fiche_attr on (j_qcode=quick_code)
417 where
418 jr_id=$1 and $filter_sql order by j_debit desc";
419 $res=$this->db->exec_sql($sql,array($this->jr_id));
420 if ( Database::num_row ($res) == 0 ) return array();
422 return $all;
423 }
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
static fetch_all($ret)
wrapper for the function pg_fetch_all
$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 447 of file acc_operation.class.php.

448 {
449 $sql="select jr_def_id from jrn where jr_id=$1";
450 $row=$this->db->get_value($sql,array($this->jr_id));
451 return $row;
452 }

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 647 of file acc_operation.class.php.

648 {
649 $ledger_id=$this->get_ledger();
650 if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
651 $oledger=new Acc_Ledger($this->db,$ledger_id);
652
653 // retrieve info from jrn_info
654
655
656 switch($oledger->get_type())
657 {
658 case 'VEN':
659 $ret=new Acc_Sold($this->db,$this->jr_id);
660 break;
661 case 'ACH':
662 $ret=new Acc_Purchase($this->db,$this->jr_id);
663 break;
664 case 'FIN':
665 $ret=new Acc_Fin($this->db,$this->jr_id);
666 break;
667 default:
668 $ret=new Acc_Misc($this->db,$this->jr_id);
669 break;
670 }
671 $ret->get();
672 if ( empty($ret->det->array))
673 {
674 $ret=new Acc_Misc($this->db,$this->jr_id);
675 $ret->get();
676 }
677 $ret->get_info();
678 return $ret;
679 }
this class manage data from the QUANT_FIN table
this class manage data from the QUANT_PURCHASE table
this class manage data from the QUANT_SOLD table

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 244 of file acc_operation.class.php.

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

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 336 of file acc_operation.class.php.

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

References $desc, $diff, $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 207 of file acc_operation.class.php.

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

References $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 793 of file acc_operation.class.php.

794 {
795 if ($p_string == "") return;
796 $a_action=explode(',',$p_string);
797 for ($i=0;$i<count($a_action);$i++)
798 {
799 $action = new Follow_Up($this->db,$a_action[$i]);
800 $action->operation=$this->jr_id;
801 $action->insert_operation();
802 }
803 }
$action

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 431 of file acc_operation.class.php.

432 {
433 $sql="update jrn set jr_comment=$1 where jr_id=$2";
434 $this->db->exec_sql($sql,array($p_text,$this->jr_id));
435 }

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 437 of file acc_operation.class.php.

438 {
439 if ( isDate($p_text) == null )
440 {
441 $p_text=null;
442 }
443 $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
444 $this->db->exec_sql($sql,array($p_text,$this->jr_id));
445 }
isDate($p_date)
Definition: ac_common.php:236

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 134 of file acc_operation.class.php.

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

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 111 of file acc_operation.class.php.

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

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 774 of file acc_operation.class.php.

775 {
776 if ( ! in_array($p_type,array('OTHER','BON_COMMANDE'))) return;
777 if (trim($p_info)=="") {
778 $this->db->exec_sql('delete from jrn_info where jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
779 return;
780 }
781 $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));
782 if ( $exist == "0" ) {
783 //insert into jrn_info
784 $this->db->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)',
785 array($this->jr_id,$p_type,$p_info));
786 } elseif ( $exist == 1) {
787 //update
788 $this->db->exec_sql('update jrn_info set ji_value=$3 where jr_id=$1 and id_type=$2',
789 array($this->jr_id,$p_type,$p_info));
790 }
791 }

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 100 of file acc_operation.class.php.

101 {
102 $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
103 array($this->jr_id));
104 return $ret;
105 }

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 394 of file acc_operation.class.php.

395 {
396 $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
397 array($p_internal));
398 if ( Database::num_row($res) == 0 ) return -1;
400 return 0;
401 }
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 863 of file acc_operation.class.php.

864 {
865 $type_operation=new ISelect("jr_optype");
866 $type_operation->value=array(
867 array(("label")=>_("Normal"), "value"=>"NOR"),
868 array(("label")=>_("Ouverture"), "value"=>"OPE"),
869 array(("label")=>_("Fermeture"), "value"=>"CLO"),
870 array(("label")=>_("Extourne"), "value"=>"EXT")
871 );
872
873 $type_operation->selected=$p_status;
874 return $type_operation;
875 }

◆ set_id()

Acc_Operation::set_id (   $p_id)

set the operation id (jrn.jr_id)

Parameters
type$p_id

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

809 {
810 if (isNumber($p_id)==0) {
811 throw new Exception(_('Acc_Operation::set_id , id invalide '));
812 }
813 $this->jr_id=$p_id;
814 }
isNumber($p_int)
Definition: ac_common.php:215

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 818 of file acc_operation.class.php.

819 {
820 // Operation
821 if ( $this->jr_id == 0 )
822 throw new Exception(_('Object invalide, id incorrect'));
823 if (
824 $this->db->get_value('select count(*) from jrn where jr_id=$1',
825 array($this->jr_id)) == 0 )
826 throw new Exception(_('Object invalide, id incorrect'));
827
828 $this->db->exec_sql("update jrn set jr_rapt = 'paid' where jr_id = $1",
829 array($this->jr_id));
830 }

References db, and jr_id.

◆ set_pj()

Acc_Operation::set_pj ( )

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

Note
if the jr_id it fails

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

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

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

+ Here is the call graph for this function:

◆ test_me()

static Acc_Operation::test_me ( )
static

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

843 {
844 $_SESSION[SESSION_KEY.'g_user']=NOALYSS_ADMINISTRATOR;
845 $_SESSION[SESSION_KEY.'g_pass']='dany';
846 global $g_user;
848 $g_user=new Noalyss_user($cn);
849 $a=new Acc_Operation($cn);
850 $a->jr_id=1444;
851 $b=$a->get_quant();
852 var_dump($b);
853 }
static connect()
NOALYSS_ADMINISTRATOR
Definition: install.php:735

References $a, $b, $cn, $g_user, Dossier\connect(), and NOALYSS_ADMINISTRATOR.

+ 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 425 of file acc_operation.class.php.

426 {
427 $sql="update jrnx set j_text=$1 where j_id=$2";
428 $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
429 }

References $sql, and db.

Field Documentation

◆ $amount

Acc_Operation::$amount

amount of the operatoin

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

Referenced by get_amount(), and get_currency_amount().

◆ $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().

◆ $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.

◆ $periode

Acc_Operation::$periode

periode to use

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

◆ $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.

◆ $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: