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

the class Acc_Ledger_Fin inherits from Acc_Ledger, this object permit to manage the financial ledger More...

+ Inheritance diagram for Acc_Ledger_Fin:
+ Collaboration diagram for Acc_Ledger_Fin:

Public Member Functions

 __construct ($p_cn, $p_init)
 construct
 
 confirm ($p_array, $p_nothing=0)
 show the result of the array to confirm before inserting
 
 get_bank ()
 find and FICHE.F_ID of the bank or -1 if not found
 
 get_bank_name ()
 return a string with the bank account, name and quick_code
 
 input ($p_array=null, $notused=0)
 display a form to enter an FIN operation
 
 insert ($p_array=null)
 
 insert_quant_fin ($p_bankid, $p_jrid, $p_otherid, $p_amount, $p_j_id_currency)
 insert into the quant_fin table
 
 numb_operation ()
 return true is we numbere each operation
 
 verify_operation ($p_array)
 Verify that the data are correct before inserting or confirming.
 
- Public Member Functions inherited from Acc_Ledger
 add_card ($p_filter, $p_id_update)
 Return a button to create new card, depending of the ledger.
 
 button_copy_operation ()
 Show a button to create an operation identical to the recorded one.
 
 button_new_operation ()
 Create a button to encode a new operation into the same ledger.
 
 check_currency ($p_qcode_payment, $p_currency_id)
 When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo reliable , all the bank operation must be in the same currency Operation = Currency 1 and Bank = Currency 2 then it must failed , except if currency 2 (of the bank is the default currency.
 
 check_currency_setting ($p_currency_code)
 Check that the currency code does exist and the setting of the folder is correct.
 
 check_payment ($e_mp, $e_mp_qcode)
 check if the payment method is valid
 
 check_periode ()
 Check if a Dossier is using the check on the periode, if true than the user has to enter the date and the periode, it is a security check.
 
 check_strict ()
 Check if a Dossier is using the strict mode or not.
 
 compute_internal_code ($p_grpt)
 compute the internal code of the saved operation and set the $this->jr_internal to the computed value
 
 convert_from_follow ($p_ag_id, $copy_description=0)
 convert operations from FOLLOWUP into a SALE , FEENOTE or PURCHASE operation into a suitable array
 
 create_document ($internal, $p_array)
 create the invoice and saved it as attachment to the operation,
 
 CurrencyInput ($p_currency_code, $p_currency_rate, $p_eur_amount)
 Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amount.
 
 delete ()
 let you delete a operation
 
 delete_ledger ()
 delete a ledger IF it doesn't contain anything
 
 display_additional_tax ($p_additional_tax, $p_amount)
 in confirm screen , display the compute value for additional tax @parameter $p_additional_tax acc_other_tax.ac_id
 
 display_ledger ()
 display detail of a ledger
 
 display_negative_warning ($p_amount)
 If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
 
 display_warning ($pa_msg, $p_warning)
 Display warning contained in an array.
 
 existing_vat ()
 return the used VAT code with a rate > 0
 
 get_all_fiche_def ()
 retrieve all the card for this type of ledger, make them into a string separated by comma
 
 get_class_def ()
 retrieve the jrn_def_class_deb and return it
 
 get_currency ()
 returns the code iso of the default currency for this ledger
 
 get_customer_late ()
 get info from customer not yet paid
 
 get_customer_now ()
 get info from customer to pay today
 
 get_default_card ($p_ledger_type, $p_side)
 Return an array of default card for the ledger type given.
 
 get_fiche_def ()
 retrieve the jrn_def_fiche and return them into a array index deb, cred
 
 get_first ($p_type, $p_access=3)
 get the first ledger
 
 get_id ($p_internal)
 retrieve the jr_id thanks the internal code, do not change anything to the current object
 
 get_is_loaded ()
 
 get_last ($p_limit)
 return the last p_limit operation into an array
 
 get_last_date ()
 get the date of the last operation
 
 get_last_pj ()
 returns the sequence number of the receipt for the current ledger or create the sequence if it doesn't exist
 
 get_ledger_id ()
 Set the jrn_def.jrn_def_id.
 
 get_min_row ()
 
 get_name ()
 Return the name of a ledger.
 
 get_operation ($p_from, $p_to)
 retrieve operation from jrn
 
 get_operation_date ($p_date, $p_ledger_type, $sql_op)
 Get operation from the ledger type before, after or with the given date .
 
 get_other_amount ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 get_propertie ()
 Get the properties of a journal.
 
 get_rowSimple ($p_from, $p_to, $pa_ledger=[], $trunc=0, $p_limit=-1, $p_offset=-1)
 Get simplified row from ledger Call Acc_Ledger_History_Generic:get_rowSimple.
 
 get_solde ($p_from, $p_to)
 get the saldo of a ledger for a specific period
 
 get_supplier_late ()
 get info from supplier not yet paid
 
 get_supplier_now ()
 get info from supplier to pay today
 
 get_tiers ($p_jrn_type, $jr_id)
 Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
 
 get_tiers_id ($p_jrn_type, $jr_id)
 Return the f_id of the tiers , called by get_tiers.
 
 get_type ()
 Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
 
 guess_pj ()
 guess what the next pj should be
 
 has_other_tax ()
 returns true if the ledger has an additional tax
 
 has_quantity ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 inc_seq_pj ()
 increment the sequence for the pj
 
 input_additional_tax ()
 form : display additional tax available for this ledger and value, set 2 values : checkbox if tax applies and value
 
 input_extra_info ()
 
 input_new ()
 display FORM to enter parameters to create a new ledger.
 
 input_paid ($p_selected, $p_amount=0, $p_date="", $p_comm="")
 Create the section payment.
 
 is_closed ($p_periode)
 check if the current ledger is closed
 
 is_enable ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 listing ()
 listing of all ledgers
 
 previous_amount ($p_to)
 retrieve amount of previous periode
 
 previous_other_tax ($p_to)
 retrieve the previous amount
 
 reverse ($p_date, $p_label)
 reverse the operation by creating the opposite one, the result is to avoid it it must be done in
 
 save ($p_array=null)
 save the operation into the jrnx,jrn, , CA and pre_def
 
 save_followup ($s_related_action)
 attach action-followups to an operation,
 
 save_new ($array)
 Insert a new ledger , member variable like jrn_def_id will changed.
 
 search_group ($p_what, $p_value)
 retreive the jr_grpt_id from a ledger
 
 select_default_currency ()
 create a select button to set the default currency for a ledger used only for empty financial ledger
 
 select_depot ($p_readonly, $p_repo)
 Let you select the repository before confirming a sale or a purchase.
 
 select_ledger ($p_type="ALL", $p_access=3, $enable=TRUE)
 Show a select list of the ledgers you can access in writing, reading or simply accessing.
 
 set_currency_id ()
 retrieve currency_id from database
 
 set_is_loaded ($is_loaded)
 
 set_ledger_id ($p_id)
 Set the jrn_def.jrn_def_id.
 
 set_quantity ($p_value)
 set quantity for the ledger to 1 or 0,
 
 update ($array=null)
 update a ledger
 
 update_internal_code ($p_internal)
 
 update_paid ($p_array)
 Update the paiment in the list of operation.
 
 use_quant_table ($p_grpt_id, $p_jrn_type)
 Check if the operation is used in the table quant*.
 
 vat_operation ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 verify_ledger ($array)
 Verify before update.
 

Additional Inherited Members

- Static Public Member Functions inherited from Acc_Ledger
static array_cat ()
 create an array of the existing cat, to be used in a checkbox form
 
static next_number ($p_cn, $p_type)
 retrieve the next number for this type of ledger
 
static test_me ($pCase='')
 this function is intended to test this class
 
- Data Fields inherited from Acc_Ledger
 $currency_id
 !< default number of rows by default 10
 
 $db
 !< jrn_def.jrn_def_id
 
 $id
 
 $ledger_type
 !< row of the ledger
 
 $nb
 !< type of the ledger ACH ODS FIN VEN or GL
 
 $row
 !< database connextion
 
- Protected Member Functions inherited from Acc_Ledger
 find_label ($p_value)
 Retrieve the label of an accounting.
 
 verify_autonumber ($p_array)
 compare given receipt number and suggested one, if different , it means that the user enters a receipt number if e_pj or e_pj_suggest is not set or empty , or if both are equals then will return true, it returns only if they exist and are different
 
 warn_manual_receipt ($p_array)
 warn if the suggested receipt and receipt are different , it means that the user tried to number himself
 
- Protected Attributes inherited from Acc_Ledger
 $is_loaded
 !< is_loaded true the ledger definition is loaded or false, it is not
 

Detailed Description

the class Acc_Ledger_Fin inherits from Acc_Ledger, this object permit to manage the financial ledger

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

Constructor & Destructor Documentation

◆ __construct()

Acc_Ledger_Fin::__construct ( $p_cn,
$p_id )

construct

Parameters
$p_cndatabase connexion
$p_idjrn.jrn_def_id

Reimplemented from Acc_Ledger.

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

39 {
40 parent::__construct($p_cn, $p_init);
41 $this->ledger_type='FIN';
42 }

Member Function Documentation

◆ confirm()

Acc_Ledger_Fin::confirm ( $p_array,
$p_readonly = 0 )

show the result of the array to confirm before inserting

Parameters
$p_arrayarray from the form
Returns
HTML string

Reimplemented from Acc_Ledger.

Definition at line 459 of file acc_ledger_fin.class.php.

460 {
461 global $g_parameter, $g_user;
462 $r="";
463 if ( ! $this->get_is_loaded()) {
464 $this->load();
465 }
466 bcscale(2);
467 extract($p_array, EXTR_SKIP);
468 $pPeriode=new Periode($this->db);
469 if ($this->check_periode()==true)
470 {
471 $pPeriode->p_id=$periode;
472 }
473 else
474 {
475 if (isDate($e_date)!=null)
476 {
477 $pPeriode->find_periode($e_date);
478 }
479 else
480 {
481 $pPeriode->p_id=$g_user->get_periode();
482 }
483 }
484
485 list ($l_date_start, $l_date_end)=$pPeriode->get_date_limit();
486 $exercice=$pPeriode->get_exercice();
487 $r.='';
488 $r.='<fieldset><legend>'._("Banque, caisse").' </legend>';
489 $r.='<div id="jrn_name_div">';
490 $r.='<h1 id="jrn_name" style="display:inline">'.$this->get_name().'</h1>';
491 $r.='</div>';
492 $r.='<TABLE width="100%">';
493 // Date
494 //--
495 $r.="<tr>";
496 if ($chdate==1)
497 $r.='<td> Date : </td><td>'.$e_date;
498 // Periode
499 //--
500 $r.="<td>";
501 $r.="Période comptable </td><td>";
502 $r.=$l_date_start.' - '.$l_date_end;
503 $r.="</td>";
504 $r.="</tr>";
505 // Ledger (p_jrn)
506 //--
507 $r.='<tr>';
508 $r.='<td> Journal </td>';
509 $this->id=$p_jrn;
510 $r.='<td>';
511 $r.=h($this->get_name());
512 $r.='</td>';
513 $r.='</tr>';
514
515 //retrieve bank name
516 $bk_id=$this->get_bank();
517
518 $fBank=new Fiche($this->db, $bk_id);
519 $e_bank_account_label=$this->get_bank_name();
520
521 $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice."')";
522
523 $acc_account=new Acc_Account_Ledger($this->db, $fBank->strAttribut(ATTR_DEF_ACCOUNT));
524 $asolde=$acc_account->get_solde_detail($filter_year);
525 $deb=$asolde['debit'];
526 $cred=$asolde['credit'];
527 $solde=bcsub($deb, $cred);
528 $new_solde=$solde;
529
530 $r.="<TR><td colspan=\"4\"> Banque ";
531 $r.=$e_bank_account_label;
532
533 $r.="</TABLE>";
534
535 $r.='</fieldset>';
536
537 $r.='<div class="myfieldset"><h1 class="legend">'._("Extrait de compte").'</h1>';
538 //--------------------------------------------------
539 // Saldo begin end
540 //-------------------------------------------------
541 $r.='<table>';
542 $r.='<tr>';
543 // Extrait
544 //--
545 $r.=tr('<td>'._("Numéro d'extrait").' </td>'.td(h($e_pj)));
546 $r.='<tr><td >'._("Solde début extrait").' </td>';
547 $r.='<td style="num">'.nbm($first_sold).'</td></tr>';
548 $r.='<tr><td>'._("Solde fin extrait").' </td>';
549 $r.='<td style="num">'.nbm($last_sold).'</td></tr>';
550 $r.='</table>';
551
552 $r.='<h1 class="legend">Opérations financières</h1>';
553 //--------------------------------------------------
554 // financial operation
555 //-------------------------------------------------
556 $r.='<TABLE style="width:100%" id="fin_item">';
557 $r.="<TR>";
558 if ($chdate==2)
559 $r.='<th>'._("Date").'</th>';
560 $r.="<th style=\"width:auto;text-align:left\" colspan=\"2\">"._("Nom")."</th>";
561 $r.="<th style=\"text-align:left\" >"._("Commentaire")."</th>";
562 $r.="<th style=\"text-align:right\">"._("Montant")."</th>";
563 $r.='<th colspan="2">'._("Op. Concernée(s)").'</th>';
564
565 /* if we use the AC */
566 if ($g_parameter->MY_ANALYTIC!='nu')
567 {
568 $anc=new Anc_Plan($this->db);
569 $a_anc=$anc->get_list();
570 $x=count($a_anc);
571 /* set the width of the col */
572 $r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
573
574 /* add hidden variables pa[] to hold the value of pa_id */
575 $r.=Anc_Plan::hidden($a_anc);
576 }
577 $r.="</TR>";
578 // Parse each " tiers"
579 $tot_amount=0;
580 //--------------------------------------------------
581 // For each items
582 //--------------------------------------------------
583 for ($i=0; $i<$nb_item; $i++)
584 {
585
586 $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:""
587 ;
588
590 continue;
591 $tiers_label="";
592 $tiers_amount=round(${"e_other$i"."_amount"}, 2);
593 $tot_amount=bcadd($tot_amount, $tiers_amount);
594 $tiers_comment=h(${"e_other$i"."_comment"});
595 // If $tiers has a value
596 $fTiers=new Fiche($this->db);
597 $fTiers->get_by_qcode($tiers);
598
599 $tiers_label=$fTiers->strAttribut(ATTR_DEF_NAME);
600
601 $r.="<TR>";
602 if ($chdate==2)
603 $r.=td(${"dateop".$i});
604 $r.="<td>".${'e_other'.$i}."</TD>";
605 // label
606 $r.='<TD style="width:25%;border-bottom:1px dotted grey;">';
607 $r.=$fTiers->strAttribut(ATTR_DEF_NAME);
608 $r.='</td>';
609 // Comment
610 $r.='<td style="width:40%">'.$tiers_comment.'</td>';
611 // amount
612 $r.='<td class="num">'.nbm($tiers_amount).'</td>';
613 // concerned
614 $r.='<td style="text-align:center">';
615 if (${"e_concerned".$i}!='')
616 {
617 $jr_internal=$this->db->get_array("select jr_internal from jrn where jr_id in (".${"e_concerned".$i}.")");
618 $comma="";
619 for ($x=0; $x<count($jr_internal); $x++)
620 {
621 $r.=$comma.HtmlInput::detail_op(${"e_concerned".$i}, $jr_internal[$x]['jr_internal']);
622 $comma=" , ";
623 }
624 }
625 $r.='</td>';
626 // encode the pa
627 if ($g_parameter->MY_ANALYTIC!='nu'&&$g_parameter->match_analytic($fTiers->strAttribut(ATTR_DEF_ACCOUNT))==1) // use of AA
628 {
629 // show form
630 $anc_op=new Anc_Operation($this->db);
631 $null=($g_parameter->MY_ANALYTIC=='op')?1:0;
632 $r.='<td>';
633 $p_mode=1;
634 $p_array['pa_id']=$a_anc;
635 /* op is the operation it contains either a sequence or a jrnx.j_id */
636 $r.=HtmlInput::hidden('op[]=', $i);
637 $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, $tiers_amount);
638 $r.='</td>';
639 }
640
641 $r.='</TR>';
642 }
643 $r.="</TABLE>";
644 $acc_currency=$this->get_currency();
645
646 // If currency is not the default one
647 if ($acc_currency->get_id()!=0)
648 {
649
650 $solde=$fBank->get_bk_balance_currency();
651 $cur=$acc_currency->get_code();
652 $cur_rate=$acc_currency->get_rate_date($e_date);
653 $default_currency=new Acc_Currency($this->db, 0);
654 // saldo
655 $r.="<table>";
656 $r.=tr(
657 td(_("Ancien solde")).
658 td(nbm($solde).$cur, 'class="num"')
659 );
660 $new_solde=bcadd($solde??0, $tot_amount??0);
661 $r.=tr(
662 td(_("Nouveau solde")).
663 td(nbm($new_solde).$cur, ' class="num"')
664 );
665 $r.=tr(
666 td(_("Difference")).
667 td(nbm($tot_amount).$cur, ' class="num"')
668 );
669 $r.=tr(
670 td(_("Taux")).
671 td($cur_rate)
672 );
673 $r.=tr(
674 td(_("Nouveau solde")).
675 td(bcdiv($new_solde, $cur_rate).$default_currency->get_code(), ' class="num"')
676 );
677 $r.='</table>';
678 }
679 else
680 {
681
682 $cur=$acc_currency->get_code();
683 // saldo
684 $r.="<table>";
685 $r.=tr(
686 td(_("Ancien solde")).
687 td(nbm($solde).$cur, 'class="num"')
688 );
689 $new_solde=bcadd($solde, $tot_amount);
690 $r.=tr(
691 td(_("Nouveau solde")).
692 td(nbm($new_solde).$cur, ' class="num"')
693 );
694 $r.=tr(
695 td(_("Difference")).
696 td(nbm($tot_amount).$cur, ' class="num"')
697 );
698
699 $r.='</table>';
700 }
701 // check for upload piece
702 $file=new IFile();
703 $file->setAlertOnSize(true);
704 $r.="<br>"._("Ajoutez une pièce justificative")." ";
705 $r.=$file->input("pj", "");
706
707 $r.='</div>';
708 //--------------------------------------------------
709 // Hidden variables
710 //--------------------------------------------------
711 $r.=dossier::hidden();
712 $r.=HtmlInput::hidden('p_jrn', $this->id);
713 $r.=HtmlInput::hidden('nb_item', $nb_item);
714 $r.=HtmlInput::hidden('last_sold', $last_sold);
715 $r.=HtmlInput::hidden('first_sold', $first_sold);
716 $r.=HtmlInput::hidden('e_pj', $e_pj);
717 $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
718 $r.=HtmlInput::hidden('e_date', $e_date);
719 $mt=microtime(true);
720 $r.=HtmlInput::hidden('mt', $mt);
721
722 if (isset($periode))
723 $r.=HtmlInput::hidden('periode', $periode);
724 $r.=dossier::hidden();
725 $r.=HtmlInput::hidden('sa', 'n', 'chdate');
726 for ($i=0; $i<$nb_item; $i++)
727 {
728 $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
729 $r.=HtmlInput::hidden('e_other'.$i, $tiers);
730 $r.=HtmlInput::hidden('e_other'.$i, $tiers);
731 $r.=HtmlInput::hidden('e_other'.$i.'_comment', ${'e_other'.$i.'_comment'});
732 $r.=HtmlInput::hidden('e_other'.$i.'_amount', ${'e_other'.$i.'_amount'});
733 $r.=HtmlInput::hidden('e_concerned'.$i, ${'e_concerned'.$i});
734 $r.=HtmlInput::hidden('dateop'.$i, ${'dateop'.$i});
735 $r.=HtmlInput::hidden('chdate', $chdate);
736 }
737
738 return $r;
739 }
isDate($p_date)
noalyss_strlentrim($p_string)
tr($p_string, $p_extra='')
Definition ac_common.php:88
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
catch(Exception $e) $exercice
_("actif, passif,charge,...")
get_bank_name()
return a string with the bank account, name and quick_code
get_bank()
find and FICHE.F_ID of the bank or -1 if not found
get_currency()
returns the code iso of the default currency for this ledger
get_name()
Return the name of a ledger.
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
static hidden($p_name, $p_value, $p_id="")
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
const ATTR_DEF_NAME
Definition constant.php:216
const ATTR_DEF_ACCOUNT
Definition constant.php:215
if(sizeof($array)==0) $pPeriode
$SecUser db
for($i=0;$i< $nb_jrn;$i++) $deb

References $anc, $cred, $deb, $default_currency, $e_date, $exercice, $file, $filter_year, $g_parameter, $g_user, $i, $p_array, $p_jrn, $periode, $pPeriode, $r, $solde, $tiers, $tot_amount, _, ATTR_DEF_ACCOUNT, ATTR_DEF_NAME, Acc_Ledger\check_periode(), db, get_bank(), get_bank_name(), Acc_Ledger\get_currency(), Acc_Ledger\get_is_loaded(), Acc_Ledger\get_name(), h, Anc_Plan\hidden(), isDate(), nbm(), noalyss_strlentrim(), td(), and tr().

+ Here is the call graph for this function:

◆ get_bank()

Acc_Ledger_Fin::get_bank ( )

find and FICHE.F_ID of the bank or -1 if not found

Definition at line 1144 of file acc_ledger_fin.class.php.

1145 {
1146 $bank_id=$this->db->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1', array($this->id));
1147 if (empty($bank_id)) return -1;
1148 return $bank_id;
1149 }

References db.

Referenced by confirm(), insert(), and verify_operation().

◆ get_bank_name()

Acc_Ledger_Fin::get_bank_name ( )

return a string with the bank account, name and quick_code

Definition at line 1131 of file acc_ledger_fin.class.php.

1132 {
1133 $this->bank_id=$this->db->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1', array($this->id));
1134 $fBank=new Fiche($this->db, $this->bank_id);
1135 $e_bank_account=" : ".$fBank->strAttribut(ATTR_DEF_BQ_NO);
1136 $e_bank_name=" : ".$fBank->strAttribut(ATTR_DEF_NAME);
1137 $e_bank_qcode=": ".$fBank->strAttribut(ATTR_DEF_QUICKCODE);
1138 return $e_bank_qcode.$e_bank_name.$e_bank_account;
1139 }
const ATTR_DEF_BQ_NO
Definition constant.php:217
const ATTR_DEF_QUICKCODE
Definition constant.php:237

References ATTR_DEF_BQ_NO, ATTR_DEF_NAME, ATTR_DEF_QUICKCODE, and db.

Referenced by confirm().

◆ input()

Acc_Ledger_Fin::input ( $p_array = null,
$notused = 0 )

display a form to enter an FIN operation

Parameters
$p_arraycontains the value usually it is $_POST
Returns
string with html code
Note
the form tag are not set here

Reimplemented from Acc_Ledger.

Definition at line 246 of file acc_ledger_fin.class.php.

247 {
248 global $g_parameter, $g_user;
249 if ($p_array!=null)
250 extract($p_array, EXTR_SKIP);
251
252 $pview_only=false;
253
254 $min_article=$this->get_min_row();
255
256 $str_add_button_tiers="";
257 $add_card=FALSE;
258 if ($g_user->check_action(FICADD)==1)
259 {
260 $add_card=TRUE;
261 }
262
263 // The first day of the periode
264 $pPeriode=new Periode($this->db);
265 list ($l_date_start, $l_date_end)=$pPeriode->get_date_limit($g_user->get_periode());
266 if ($g_parameter->MY_DATE_SUGGEST=='Y')
267 $op_date=(!isset($e_date) )?$l_date_start:$e_date;
268 else
269 $op_date=(!isset($e_date) )?'':$e_date;
270
271 $r="";
272
273 $r.=dossier::hidden();
274 $f_legend='Banque, caisse';
275 // Date
276 //--
277 $Date=new IDate("e_date", $op_date);
278 $Date->setReadOnly($pview_only);
279 $f_date=$Date->input();
280 $f_period='';
281 if ($this->check_periode()==true)
282 {
283 // Periode
284 //--
285 $l_user_per=(isset($periode))?$periode:$g_user->get_periode();
286 $period=new IPeriod();
287 $period->cn=$this->db;
288 $period->type=OPEN;
289 $period->value=$l_user_per;
290 $period->user=$g_user;
291 $period->name='periode';
292 try
293 {
294 $l_form_per=$period->input();
295 }
296 catch (Exception $e)
297 {
298 if ($e->getCode()==1)
299 {
300 throw new Exception(_("Aucune période ouverte"));
301 }
302 }
304 $f_period="Période comptable $label".$l_form_per;
305 }
306
307 // Ledger (p_jrn)
308 //--
309 $onchange="update_bank();ajax_saldo('first_sold');update_name();update_row('fin_item');show_ledger_fin_currency();";
310
311 if ($g_parameter->MY_DATE_SUGGEST=='Y')
312 $onchange.='get_last_date();';
313 if ($g_parameter->MY_PJ_SUGGEST=='Y')
314 $onchange.='update_receipt();';
315
316 $add_js='onchange="'.$onchange.'"';
317 $wLedger=$this->select_ledger('FIN', 2, FALSE);
318 if ($wLedger==null)
319 throw new Exception(_('Pas de journal disponible'));
320
321 $wLedger->javascript=$add_js;
322
323 $label_ledger=_("Journal")." ".Icon_Action::infobulle(2);
324
325 // retrieve bank name, code and account from the jrn_def.jrn_def_bank
326
327 $f_bank='<span id="bkname">'.$this->get_bank_name().'</span>';
328 if ($this->bank_id=="")
329 {
330 echo h2("Journal de banque non configuré ".$this->get_name(), ' class="error"');
331 echo '<span class="error"> vous devez donner à ce journal un compte en banque (fiche), modifiez dans C0JRN</span>';
332 alert("Journal de banque non configuré ".$this->get_name());
333 }
334
335 $f_legend_detail='Opérations financières';
336 //--------------------------------------------------
337 // Saldo begin end
338 //-------------------------------------------------
339 // Extrait
340 $default_pj='';
341 if ($g_parameter->MY_PJ_SUGGEST=='Y')
342 {
343 $default_pj=$this->guess_pj();
344 }
345 $wPJ=new IText('e_pj');
346 $wPJ->readonly=false;
347 $wPJ->size=10;
348 $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
349
350 $f_extrait=$wPJ->input().HtmlInput::hidden('e_pj_suggest', $default_pj);
352
353 $first_sold=(isset($first_sold))?$first_sold:"";
354 $wFirst=new INum('first_sold', $first_sold);
355
356 $last_sold=isset($last_sold)?$last_sold:"";
357 $wLast=new INum('last_sold', $last_sold);
358
359 $max=(isset($nb_item))?$nb_item:$min_article;
360
361 $r.=HtmlInput::hidden('nb_item', $max);
362 //--------------------------------------------------
363 // financial operation
364 //-------------------------------------------------
365
366 $array=array();
367 // Parse each " tiers"
368 for ($i=0; $i<$max; $i++)
369 {
370 $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
371
372 $tiers_amount=(isset(${"e_other$i"."_amount"}))?round(${"e_other$i"."_amount"}, 2):0;
373
374 $tiers_comment=(isset(${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:"";
375
376 $operation_date=new IDate("dateop".$i);
377 $operation_date->value=(isset(${'dateop'.$i}))?${'dateop'.$i}:"";
378 $array[$i]['dateop']=$operation_date->input();
379 ${"e_other$i"."_amount"}=(isset(${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
380
381 $W1=new ICard();
382 $W1->label="";
383 $W1->name="e_other".$i;
384 $W1->id="e_other".$i;
385 $W1->value=$tiers;
386 $W1->extra='deb'; // credits
387 $W1->typecard='deb';
388 $W1->set_dblclick("fill_ipopcard(this);");
389 $W1->set_attribute('ipopup', 'ipopcard');
390
391 // name of the field to update with the name of the card
392 $W1->set_attribute('label', 'e_other_name'.$i);
393 // name of the field to update with the name of the card
394 $W1->set_attribute('typecard', 'filter');
395 // Add the callback function to filter the card on the jrn
396 $W1->set_callback('filter_card');
397 $W1->set_function('fill_data');
398 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
399 $W1->readonly=$pview_only;
400 $array[$i]['qcode']=$W1->input();
401 $array[$i]['search']=$W1->search();
402 $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("deb", $W1->id):"";
403 // Card name
404 //
405 $card_name="";
406 if ($tiers!="")
407 {
408 $fiche=new Fiche($this->db);
409 $fiche->get_by_qcode($tiers);
410 $card_name=$this->db->get_value("Select ad_value from fiche_detail where ad_id=$1 and f_id=$2",
411 array(ATTR_DEF_NAME, $fiche->id));
412 }
413
414 $wcard_name=new IText("e_other_name".$i, $card_name);
415 $wcard_name->id=$wcard_name->name;
416 $wcard_name->readOnly=true;
417 $array[$i]['cname']=$wcard_name->input();
418
419 // Comment
420 $wComment=new IText("e_other$i"."_comment", $tiers_comment);
421 $wComment->style='class="input_text label_item"';
422
423 $wComment->setReadOnly($pview_only);
424 $array[$i]['comment']=$wComment->input();
425 // amount
426 $wAmount=new INum("e_other$i"."_amount", $tiers_amount);
427
428 $wAmount->size=7;
429 $wAmount->setReadOnly($pview_only);
430 $array[$i]['amount']=$wAmount->input();
431 // concerned
432 ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:""
433 ;
434 $wConcerned=new IConcerned("e_concerned".$i, ${"e_concerned".$i});
435 $wConcerned->tiers="e_other".$i;
436 $wConcerned->setReadOnly($pview_only);
437 $wConcerned->amount_id="e_other".$i."_amount";
438
439 $wConcerned->paid='paid';
440 $array[$i]['concerned']=$wConcerned->input();
441 }
442
443 ob_start();
444 require_once NOALYSS_TEMPLATE.'/form_ledger_fin.php';
445 $r.=ob_get_contents();
446 ob_end_clean();
447 $r.=create_script("$('".$Date->id."').focus()");
448
449 return $r;
450 }
h2($p_string, $p_class="", $raw="")
Definition ac_common.php:68
alert($p_msg, $buffer=false)
alert in javascript
select_ledger($p_type="ALL", $p_access=3, $enable=TRUE)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
$db
!< jrn_def.jrn_def_id
guess_pj()
guess what the next pj should be
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
const OPEN
Definition constant.php:201
const FICADD
create_script($p_string)
create the HTML for adding the script tags around of the script

References $array, Acc_Ledger\$db, $e, $e_date, $fiche, $g_parameter, $g_user, $i, $label, $max, $p_array, $periode, $pPeriode, $r, $tiers, $wLedger, _, Acc_Ledger\add_card(), alert(), ATTR_DEF_NAME, Acc_Ledger\check_periode(), create_script(), db, FICADD, Acc_Ledger\get_min_row(), Acc_Ledger\get_name(), Acc_Ledger\guess_pj(), h2(), Icon_Action\infobulle(), OPEN, Acc_Ledger\select_ledger(), and HtmlInput\setReadOnly().

+ Here is the call graph for this function:

◆ insert()

Acc_Ledger_Fin::insert ( $p_array = null)

save also into quant_fin

Definition at line 747 of file acc_ledger_fin.class.php.

748 {
749 global $g_parameter;
750
751 if ( ! $this->get_is_loaded()) {
752 $this->load();
753 }
754 bcscale(2);
755 $internal_code="";
756 $oid=0;
757 extract($p_array, EXTR_SKIP);
758 $ret='';
759 // Debit = banque
760 $bank_id=$this->get_bank();
761 $fBank=new Fiche($this->db, $bank_id);
762 $e_bank_account=$fBank->strAttribut(ATTR_DEF_QUICKCODE);
763 // Get the saldo
764 $pPeriode=new Periode($this->db);
765 $sposte=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
766 // if 2 accounts, take only the debit one for customer
767 if (strpos($sposte, ',')!=0)
768 {
769 $array=explode(',', $sposte);
770 $poste_val=$array[0];
771 }
772 else
773 {
774 $poste_val=$sposte;
775 }
776
777 $acc_account=new Acc_Account_Ledger($this->db, $poste_val);
778
779 // If date = deposit date
780 if ($chdate==1)
781 {
782 if ($this->check_periode()==true)
783 {
784 $pPeriode->p_id=$periode;
785 }
786 else
787 {
788 $pPeriode->find_periode($e_date);
789 }
790 $exercice=$pPeriode->get_exercice();
791 $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice."')";
792 $asolde=$acc_account->get_solde_detail($filter_year);
793 $deb=$asolde['debit'];
794 $cred=$asolde['credit'];
795 $solde=bcsub($deb, $cred);
796 $new_solde=$solde;
797 }
798
799
800
801
802 try
803 {
804 $this->db->start();
805 $amount=0.0;
806 $idx_operation=0;
807 $ret='<table class="result" >';
808 $ret.=tr(th(_('Date')).th(_('n° interne')).th(_('Quick Code'))
809 .th(_('Nom')).th(_('Libellé')).th(_('Montant'), ' style="text-align:right"'));
810 // Credit = goods
811 $get_solde=true;
812
813 $acc_currency=new Acc_Currency($this->db, $this->currency_id);
814
815 // get the currency_rate when we have one date for all the operations
816 if ($chdate!=2)
817 {
818 $currency_rate=$acc_currency->get_rate_date($e_date);
819 }
820 if (DEBUGNOALYSS>1)
821 {
822 printf("<p> currency_id %s </p>",$this->currency_id);
823 printf("<p> rate %s </p>", $currency_rate);
824 }
825 // for each item
826 for ($i=0; $i<$nb_item; $i++)
827 {
828 // insert it into the database
829 // and quit the loop ?
830 if (noalyss_strlentrim(${"e_other$i"})==0)
831 continue;
832
833 // get the currency_rate when each operation has its own date
834 if ($chdate==2)
835 {
836 $e_date=${'dateop'.$i};
837 $currency_rate=$acc_currency->get_rate_date($e_date);
838 }
839 // if date is date of operation
840 if ($chdate==2&&$get_solde)
841 {
842 $get_solde=false;
843 if ($this->check_periode()==true&&isset($p_array['periode']))
844 {
845 $pPeriode->p_id=$periode;
846 }
847 else
848 {
849 $pPeriode->find_periode($e_date);
850 }
851 $exercice=$pPeriode->get_exercice();
852 $filter_year=" j_tech_per in (select p_id from parm_periode where p_exercice='".
853 sql_string($exercice)."')";
854 $solde=$acc_account->get_solde($filter_year);
855 $new_solde=$solde;
856 }
857 $fPoste=new Fiche($this->db);
858 $fPoste->get_by_qcode(${"e_other$i"});
859
860 // convert to EUR if needed and round it
861 $amount_input=${"e_other$i"."_amount"}=round(${"e_other$i"."_amount"}, 2);
862 $amount_eur=bcdiv($amount_input, $currency_rate);
863
864 $amount=bcadd($amount, $amount_input);
865
866 // Record a line for the bank
867 // Compute the j_grpt
868 $seq=$this->db->get_next_seq('s_grpt');
869
870 $acc_operation=new Acc_Operation($this->db);
871 $acc_operation->date=$e_date;
872 $sposte=$fPoste->strAttribut(ATTR_DEF_ACCOUNT);
873 // if 2 accounts
874 if (strpos($sposte, ',')!=0)
875 {
876 $array=explode(',', $sposte);
877 if (${"e_other$i"."_amount"}<0)
878 $poste_val=$array[1];
879 else
880 $poste_val=$array[0];
881 }
882 else
883 {
884 $poste_val=$sposte;
885 }
886
887
888 $acc_operation->poste=$poste_val;
889 $acc_operation->amount=bcmul($amount_eur, -1);
890 $acc_operation->grpt=$seq;
891 $acc_operation->jrn=$p_jrn;
892 $acc_operation->type='d';
893
894 if (isset($periode))
895 $tperiode=$periode;
896 else
897 {
898 $per=new Periode($this->db);
899 $tperiode=$per->find_periode($e_date);
900 }
901 $acc_operation->periode=$tperiode;
902 $acc_operation->qcode=${"e_other".$i};
903 $j_id_currency=$acc_operation->insert_jrnx();
904
905 // -- Insert into Operation Currency
906 $operation_currency=new Operation_currency_SQL($this->db);
907 $operation_currency->oc_amount=$amount_input;
908 $operation_currency->oc_vat_amount=0;
909 $operation_currency->oc_price_unit=0;
910 $operation_currency->j_id=$j_id_currency;
911 $operation_currency->insert();
912
913 $acc_operation=new Acc_Operation($this->db);
914 $acc_operation->date=$e_date;
915 $sposte=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
916
917 // if 2 accounts, use the first one if DEB otherwise the second one
918 if (strpos($sposte, ',')!=0)
919 {
920 $array=explode(',', $sposte);
921 if (${"e_other$i"."_amount"}<0)
922 $poste_val=$array[1];
923 else
924 $poste_val=$array[0];
925 }
926 else
927 {
928 $poste_val=$sposte;
929 }
930
931 $acc_operation->poste=$poste_val;
932 $acc_operation->amount=$amount_eur;
933 $acc_operation->grpt=$seq;
934 $acc_operation->jrn=$p_jrn;
935 $acc_operation->type='d';
936 $acc_operation->periode=$tperiode;
937 $acc_operation->qcode=$e_bank_account;
938 $j_id=$acc_operation->insert_jrnx();
939
940 // -- Insert into Operation Currency
941 $operation_currency=new Operation_currency_SQL($this->db);
942 $operation_currency->oc_amount=$amount_input;
943 $operation_currency->oc_vat_amount=0;
944 $operation_currency->oc_price_unit=0;
945 $operation_currency->j_id=$j_id;
946 $operation_currency->insert();
947
948 if (sql_string(${"e_other$i"."_comment"})==null)
949 {
950 // if comment is blank set a default one
951 $comment=sprintf(_(" compte : %s a %s "), $fBank->strAttribut(ATTR_DEF_NAME),
952 $fPoste->strAttribut(ATTR_DEF_NAME)
953 );
954 }
955 else
956 {
957 $comment=strip_tags(${'e_other'.$i.'_comment'});
958 }
959
960
961 $acc_operation=new Acc_Operation($this->db);
962 $acc_operation->jrn=$p_jrn;
963 $acc_operation->amount=abs($amount_eur);
964 $acc_operation->date=$e_date;
965 $acc_operation->desc=$comment;
966 $acc_operation->grpt=$seq;
967 $acc_operation->periode=$tperiode;
968 $acc_operation->mt=$mt;
969 $idx_operation++;
970 $acc_operation->pj='';
971 $acc_operation->currency_id=$this->currency_id;
972 $acc_operation->currency_rate=$currency_rate;
973 $acc_operation->currency_rate_ref=$currency_rate;
974
975 if (trim($e_pj)!=''&&$this->numb_operation()==true)
976 $acc_operation->pj=$e_pj.str_pad($idx_operation, 3, 0, STR_PAD_LEFT);
977
978 if (trim($e_pj)!=''&&$this->numb_operation()==false)
979 $acc_operation->pj=$e_pj;
980
981 $jr_id=$acc_operation->insert_jrn();
982 if ( $jr_id == false )
983 throw new Exception (_("Erreur de balance"),EXC_BALANCE);
984
985 // $acc_operation->update_receipt();
986 $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id));
987 $internal=$this->compute_internal_code($seq);
988
989 if (trim(${"e_concerned".$i})!="")
990 {
991 if (strpos(${"e_concerned".$i}, ',')!=0)
992 {
993 $aRapt=explode(',', ${"e_concerned".$i});
994 foreach ($aRapt as $rRapt)
995 {
996 // Add a "concerned operation to bound these op.together
997 //
998 $rec=new Acc_Reconciliation($this->db);
999 $rec->set_jr_id($jr_id);
1000
1001 if (isNumber($rRapt)==1)
1002 {
1003 $rec->insert($rRapt);
1004 try
1005 {
1006 $oppaid=new Acc_Operation($this->db);
1007 $oppaid->set_id($rRapt);
1008 $oppaid->set_paid();
1009 }
1010 catch (Exception $ex)
1011 {
1012 record_log($ex->getTraceAsString());
1013 echo _('Attention , erreur Acc_Ledger_Fin::insert , coche paiement');
1014 }
1015 }
1016 }
1017 }
1018 else
1019 if (isNumber(${"e_concerned".$i})==1)
1020 {
1021 $rec=new Acc_Reconciliation($this->db);
1022 $rec->set_jr_id($jr_id);
1023 $rec->insert(${"e_concerned$i"});
1024 try
1025 {
1026 $oppaid=new Acc_Operation($this->db);
1027 $oppaid->set_id(${"e_concerned".$i});
1028 $conc_amount=$oppaid->get_amount();
1029 if ($conc_amount==$acc_operation->amount)
1030 {
1031 $oppaid->set_paid();
1032 }
1033 }
1034 catch (Exception $ex)
1035 {
1036 record_log($ex->getTraceAsString());
1037 echo _('Attention , erreur Acc_Ledger_Fin::insert , coche paiement');
1038 }
1039 }
1040 }
1041
1042 // Set Internal code
1043 $this->grpt_id=$seq;
1044 /**
1045 * save also into quant_fin
1046 */
1047 $this->insert_quant_fin($fBank->id, $jr_id, $fPoste->id, $amount_eur, $j_id_currency);
1048
1049 if ($g_parameter->MY_ANALYTIC!="nu")
1050 {
1051 // for each item, insert into operation_analytique */
1052 $op=new Anc_Operation($this->db);
1053 $op->set_currency_rate($currency_rate);
1054 $op->oa_group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
1055 $op->j_id=$j_id_currency;
1056 $op->oa_date=$e_date;
1057 $op->oa_debit='f';
1058 $op->oa_description=sql_string($comment);
1059 $op->save_form_plan($_POST, $i, $j_id_currency);
1060 }
1061
1062
1063 $this->update_internal_code($internal);
1064
1066 // Compute display
1067 $row=td($e_date)
1068 .td($js_detail)
1069 .td(${"e_other$i"})
1070 .td($fPoste->strAttribut(ATTR_DEF_NAME))
1071 .td(${"e_other".$i."_comment"})
1072 .td(nbm(${"e_other$i"."_amount"}), 'class="num"');
1073 $class=($i%2==0)?' class="even" ':' class="odd" ';
1074 $ret.=tr($row, $class);
1075
1076 if ($i==0)
1077 {
1078 // first record we upload the files and
1079 // keep variable to update other row of jrn
1080 if (isset($_FILES['pj']))
1081 $oid=$this->db->save_receipt($seq);
1082 }
1083 else
1084 {
1085 if ($oid!=0)
1086 {
1087 $this->db->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2,
1088 jr_pj_type=$3 where jr_grpt_id=$4",
1089 array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq));
1090 }
1091 }
1092 } // for nbitem
1093 // increment pj
1094 if (noalyss_strlentrim($e_pj)!=0)
1095 {
1096 $this->inc_seq_pj();
1097 }
1098 $ret.='</table>';
1099 }
1100 catch (Exception $e)
1101 {
1102
1103 $this->db->rollback();
1104 record_log($e);
1105 throw $e;
1106 }
1107 $this->db->commit();
1108 if ($acc_currency->get_id()==0)
1109 {
1110 $r="";
1111 $r.=sprintf("<br>"._("Ancien solde %s %s"), nbm($solde), $acc_currency->get_code());
1112 $new_solde=bcadd($new_solde, $amount);
1113 $r.=sprintf("<br>"._("Nouveau solde %s %s"), nbm($new_solde), $acc_currency->get_code());
1114 $ret.=$r;
1115 }
1116 else
1117 {
1118 $solde_cur=$fBank->get_bk_balance_currency();
1119 $r="";
1120 $r.=sprintf("<br>"._("Ancien solde %s %s"), nbm($solde_cur), $acc_currency->get_code());
1121 $new_solde=bcadd($solde_cur, $amount);
1122 $r.=sprintf("<br>"._("Nouveau solde %s %s"), nbm($new_solde), $acc_currency->get_code());
1123 $ret.=$r;
1124 }
1125 return $ret;
1126 }
isNumber($p_int)
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
sql_string($p_string)
Fix the problem with the quote char for the database.
$op
$jr_id
$ex
insert_quant_fin($p_bankid, $p_jrid, $p_otherid, $p_amount, $p_j_id_currency)
insert into the quant_fin table
numb_operation()
return true is we numbere each operation
$currency_id
!< default number of rows by default 10
inc_seq_pj()
increment the sequence for the pj
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
$row
!< database connextion
update_internal_code($p_internal)
static detail_op($p_jr_id, $p_mesg)
return a string containing the html code for calling the modifyOperation
const EXC_BALANCE
Definition constant.php:349
$_POST['ac']
Definition do.php:312

References $_POST, $amount, $array, $class, $cred, Acc_Ledger\$currency_id, $deb, $e, $e_date, $ex, $exercice, $filter_year, $g_parameter, $i, $j_id, $jr_id, $js_detail, $op, $p_array, $p_jrn, $per, $periode, $pPeriode, $r, $ret, Acc_Ledger\$row, $seq, $solde, _, ATTR_DEF_ACCOUNT, ATTR_DEF_NAME, ATTR_DEF_QUICKCODE, Acc_Ledger\check_periode(), Acc_Ledger\compute_internal_code(), db, EXC_BALANCE, get_bank(), Acc_Ledger\get_is_loaded(), Acc_Ledger\inc_seq_pj(), insert_quant_fin(), isNumber(), nbm(), noalyss_strlentrim(), numb_operation(), record_log(), sql_string(), td(), th(), tr(), and Acc_Ledger\update_internal_code().

+ Here is the call graph for this function:

◆ insert_quant_fin()

Acc_Ledger_Fin::insert_quant_fin ( $p_bankid,
$p_jrid,
$p_otherid,
$p_amount,
$p_j_id_currency )

insert into the quant_fin table

Parameters
integer$bank_idis the f_id of the bank
integer$jr_idis the jrn.jr_id of the operation
integer$otheris the f_id of the benefit
integer$amountis the amount
integer$p_j_idis the j_id of the operation

Definition at line 1170 of file acc_ledger_fin.class.php.

1171 {
1172 $sql="INSERT INTO quant_fin(qf_bank, jr_id, qf_other, qf_amount,j_id)
1173 VALUES ($1, $2, $3, $4,$5);";
1174
1175 $this->db->exec_sql($sql, array($p_bankid, $p_jrid, $p_otherid, round($p_amount, 2), $p_j_id_currency));
1176 }

References $sql, and db.

Referenced by insert().

◆ numb_operation()

Acc_Ledger_Fin::numb_operation ( )

return true is we numbere each operation

Definition at line 1154 of file acc_ledger_fin.class.php.

1155 {
1156 $a=$this->db->get_value('select jrn_def_num_op from jrn_def where jrn_def_id=$1', array($this->id));
1157 if ($a==1)
1158 return true;
1159 return false;
1160 }

References $a, and db.

Referenced by insert().

◆ verify_operation()

Acc_Ledger_Fin::verify_operation ( $p_array)

Verify that the data are correct before inserting or confirming.

Parameters
anarray (usually $_POST)
Returns
String
Exceptions
Exceptionon error occurs

Reimplemented from Acc_Ledger.

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

51 {
52 global $g_user;
53 if (is_array($p_array)==false||empty($p_array))
54 throw new Exception("Array empty");
55 /*
56 * Check needed value
57 */
58 check_parameter($p_array, 'p_jrn');
59
60 extract($p_array, EXTR_SKIP);
61 /* check for a double reload */
62 if (isset($mt)&&$this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt))!=0)
63 throw new Exception(_('Double Encodage'), 5);
64
65 /* check if we can write into this ledger */
66 if ($g_user->check_jrn($p_jrn)!='W')
67 throw new Exception(_('Accès interdit'), 20);
68
69 /* check if there is a bank account linked to the ledger */
70 $bank_id=$this->get_bank();
71
72 if ($this->db->count()==0)
73 throw new Exception("Ce journal n'a pas de compte en banque, allez dans paramètre->journal pour régler cela");
74 /* check if the accounting of the bank is correct */
75 $fBank=new Fiche($this->db, $bank_id);
76 $bank_accounting=$fBank->strAttribut(ATTR_DEF_ACCOUNT);
77 if (trim($bank_accounting)=='')
78 throw new Exception('Le poste comptable du compte en banque de ce journal est invalide');
79
80 /* check if the account exists */
81 $poste=new Acc_Account_Ledger($this->db, $bank_accounting);
82 if ($poste->load()==false)
83 throw new Exception('Le poste comptable du compte en banque de ce journal est invalide');
84 if ($chdate!=1&&$chdate!=2)
85 throw new Exception('Le choix de date est invalide');
86 if ($chdate==1)
87 {
88 /* check if the date is valid */
89 if (isDate($e_date)==null)
90 {
91 throw new Exception('Date invalide', 2);
92 }
93 $oPeriode=new Periode($this->db);
94 if ($this->check_periode()==false)
95 {
96 $periode=$oPeriode->find_periode($e_date);
97 }
98 else
99 {
100 $oPeriode->p_id=$periode;
101 list ($min, $max)=$oPeriode->get_date_limit();
102 if (cmpDate($e_date, $min)<0||
103 cmpDate($e_date, $max)>0)
104 throw new Exception(_('Date et periode ne correspondent pas'), 6);
105 }
106
107 /* check if the periode is closed */
108 if ($this->is_closed($periode)==1)
109 {
110 throw new Exception(_('Periode fermee'), 6);
111 }
112
113 /* check if we are using the strict mode */
114 if ($this->check_strict()==true)
115 {
116 /* if we use the strict mode, we get the date of the last
117 operation */
118 $last_date=$this->get_last_date();
119 if ($last_date!=null&&cmpDate($e_date, $last_date)<0)
120 throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
121 .$last_date._(' vous ne pouvez pas encoder à une date antérieure'), 15);
122 }
123 }
124
125 $acc_pay=new Acc_Operation($this->db);
126
127 $nb=0;
128 $tot_amount=0;
129 //----------------------------------------
130 // foreach item
131 //----------------------------------------
132 for ($i=0; $i<$nb_item; $i++)
133 {
134 if (noalyss_strlentrim(${'e_other'.$i})==0)
135 continue;
136 /* check if all card has a ATTR_DEF_ACCOUNT */
137 $fiche=new Fiche($this->db);
138 $fiche->get_by_qcode(${'e_other'.$i});
139 if ($fiche->get_f_enable() == '0')
140 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"),${'e_other'.$i}), 50);
141 /* check if amount are numeric and */
142 if (isNumber(${'e_other'.$i.'_amount'})==0)
143 throw new Exception('La fiche '.${'e_other'.$i}.'a un montant invalide ['.${'e_other'.$i.'_amount'}.']',
144 6);
145
146 /* compute the total */
147 $tot_amount+=round(${'e_other'.$i.'_amount'}, 2);
148
149 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT)==true)
150 throw new Exception('La fiche '.${'e_other'.$i}.'n\'a pas de poste comptable', 8);
151
152 $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
153 // if 2 accounts, take only the debit one for customer
154 if (strpos($sposte, ',')!=0)
155 {
156 $array=explode(',', $sposte);
157 $poste_val=$array[1];
158 }
159 else
160 {
161 $poste_val=$sposte;
162 }
163 /* The account exists */
164 $poste=new Acc_Account_Ledger($this->db, $poste_val);
165 if ($poste->load()==false)
166 {
167 throw new Exception('Pour la fiche '.${'e_other'.$i}.' le poste comptable ['.$poste->id.'n\'existe pas',
168 9);
169 }
170 /* Check if the card belong to the ledger */
171 $fiche=new Fiche($this->db);
172 $fiche->get_by_qcode(${'e_other'.$i});
173 if ($fiche->belong_ledger($p_jrn, 'deb')!=1)
174 throw new Exception('La fiche '.${'e_other'.$i}.'n\'est pas accessible à ce journal', 10);
175 if ($chdate==2)
176 {
177 {/* check if the date is valid */
178 if (isDate(${'dateop'.$i})==null)
179 {
180 throw new Exception('Date invalide', 2);
181 }
182 $oPeriode=new Periode($this->db);
183 if ($this->check_periode()==false)
184 {
185 $periode=$oPeriode->find_periode(${'dateop'.$i});
186 }
187 else
188 {
189 $oPeriode->p_id=$periode;
190 list ($min, $max)=$oPeriode->get_date_limit();
191 if (cmpDate(${'dateop'.$i}, $min)<0||
192 cmpDate(${'dateop'.$i}, $max)>0)
193 throw new Exception(_('Date et periode ne correspondent pas'), 6);
194 }
195
196 /* check if the periode is closed */
197 if ($this->is_closed($periode)==1)
198 {
199 throw new Exception(_('Periode fermee'), 6);
200 }
201
202 /* check if we are using the strict mode */
203 if ($this->check_strict()==true)
204 {
205 /* if we use the strict mode, we get the date of the last
206 operation */
207 $last_date=$this->get_last_date();
208 if ($last_date!=null&&cmpDate(${'dateop'.$i}, $last_date)<0)
209 throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
210 .$last_date._(' vous ne pouvez pas encoder à une date antérieure'), 15);
211 }
212 }
213 }
214 $nb++;
215 }
216 if ($nb==0)
217 throw new Exception('Il n\'y a aucune opération', 12);
218
219 /* Check if the last_saldo and first_saldo are correct */
220 if (noalyss_strlentrim($last_sold)!=0&&isNumber($last_sold)&&noalyss_strlentrim($first_sold)!=0&&isNumber($first_sold)
221 )
222 {
223 $diff=bcsub($last_sold,$first_sold,2);
224 $diff=bcsub($diff,$tot_amount,2);
225 $calc=bcadd($first_sold, $tot_amount, 2);
226 if ($first_sold!=0||$last_sold!=0)
227 {
228 if ($diff!=0)
229 {
230 throw new Exception(sprintf(_('Le montant de l\'extrait est incorrect,'.
231 " solde donné [ %s ]".
232 " solde calculé [%s] , différence de [%s]"), $last_sold, $calc,
233 $diff), 13);
234 }
235 }
236 }
237 }
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
$nb
!< type of the ledger ACH ODS FIN VEN or GL
is_closed($p_periode)
check if the current ledger is closed
get_last_date()
get the date of the last operation
check_strict()
Check if a Dossier is using the strict mode or not.
$oPeriode
Definition do.php:156
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...

References $array, $diff, $e_date, $fiche, $g_user, $i, $max, $min, Acc_Ledger\$nb, $oPeriode, $p_array, $p_jrn, $periode, $poste, $tot_amount, _, ATTR_DEF_ACCOUNT, check_parameter(), Acc_Ledger\check_periode(), Acc_Ledger\check_strict(), cmpDate(), db, get_bank(), Acc_Ledger\get_last_date(), Acc_Ledger\is_closed(), isDate(), isNumber(), and noalyss_strlentrim().

+ Here is the call graph for this function:

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