noalyss Version-9
anc_account.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PhpCompta is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2002-2021) Author Dany De Bontridder <danydb@noalyss.eu>
21
22/**
23 * @file
24 * @brief Analytic account
25 */
26/**
27 * @class Anc_Account
28 * @brief Analytic account ; get the balance
29 */
31{
32
34
35 public function __construct($p_cn, $p_id=-1)
36 {
37 $this->poste_analytique_sql=new Poste_analytique_SQL($p_cn, $p_id);
38 }
39
40 public function get_poste_analytique_sql()
41 {
43 }
44
46 {
47 $this->poste_analytique_sql=$poste_analytique_sql;
48 }
49 /**
50 * @brief Get the balance of an Analytic account
51 * @param string $p_cond_sql SQL condition to filter , usually the period
52 * @see Impress::compute_amount
53 * @return array key = credit , debit , solde
54 */
55 public function get_balance($p_cond_sql)
56 {
57 if ( DEBUGNOALYSS > 1)
58 {
59 tracedebug("impress.debug.log", "$p_cond_sql", 'Anc_Account->get_balance \$p_cond_sql');
60 }
61 $cn=$this->poste_analytique_sql->cn;
62 $detail=$cn->get_row("
63 select ( select coalesce (sum(oa1.oa_amount),0)
64 from operation_analytique oa1
65 where oa1.po_id=$1
66 and oa1.oa_debit='t'
67 $p_cond_sql
68 ) as debit,
69 ( select coalesce (sum(oa2.oa_amount),0)
70 from operation_analytique oa2
71 where oa2.po_id=$1
72 and oa2.oa_debit='f'
73 $p_cond_sql
74 ) as credit
75 ",[$this->poste_analytique_sql->getp("po_id")]);
76 if ( DEBUGNOALYSS > 1)
77 {
78 tracedebug("impress.debug.log", $cn->sql, 'Anc_Account->get_balance SQL executed');
79 }
80 $tdetail['credit']=$detail['credit'];
81 $tdetail['debit']=$detail['debit'];
82 $tdetail['solde']=abs(bcsub($detail['debit'],$detail['credit']));
83 return $tdetail;
84
85
86 }
87 /**
88 * @brief retrieve the Analytic account thanks its code
89 * @param type $p_code
90 * @return type
91 */
92 public function load_by_code($p_code)
93 {
94 $cn=$this->poste_analytique_sql->cn;
95 $p_id= $cn->get_value("select po_id from poste_analytique where po_name=$1",
96 [ trim(strtoupper($p_code))]);
97 $p_id=(empty($p_id))?-1:$p_id;
98 $this->poste_analytique_sql->setp('po_id',$p_id);
99 $this->poste_analytique_sql->load();
101 }
102
103}
Analytic account ; get the balance.
__construct($p_cn, $p_id=-1)
set_poste_analytique_sql($poste_analytique_sql)
get_balance($p_cond_sql)
Get the balance of an Analytic account.
load_by_code($p_code)
retrieve the Analytic account thanks its code
abstract of the table public.poste_analytique