noalyss Version-9
customer.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20require_once NOALYSS_INCLUDE.'/constant.php';
21require_once NOALYSS_INCLUDE.'/lib/user_common.php';
22/*! \file
23 * \brief Derived from class fiche Customer are a specific kind of card
24 */
25/*!
26 * \brief class Customer are a specific kind of card
27 */
28
29// Use the view vw_customer
30//
31class Customer extends Fiche
32{
33
34 var $poste; /*!< $poste poste comptable */
35 var $name; /*!< $name name of the company */
36 var $street; /*!< $street Street */
37 var $country; /*!< $country Country */
38 var $cp; /*!< $cp Zip code */
39 var $vat_number; /*!< $vat_number vat number */
40
41 /*! \brief Constructor
42 /* only a db connection is needed */
43 function __construct($p_cn,$p_id=0)
44 {
45 $this->fiche_def_ref=FICHE_TYPE_CLIENT;
46 parent::__construct($p_cn,$p_id) ;
47
48 }
49 /*! \brief Get all info contains in the view
50 * thanks to the poste elt (account)
51 */
52 function get_by_account($p_poste=0)
53 {
54 $this->poste=($p_poste==0)?$this->poste:$p_poste;
55 $sql="select * from vw_client where poste_comptable=$1";
56 $Res=$this->cn->exec_sql($sql,array($this->poste));
57 if ( Database::num_row($Res) == 0) return null;
58 if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs fiches avec le même poste',1);
59 // There is only _one_ row by customer
61 $this->name=$row['name'];
62 $this->id=$row['f_id'];
63 $this->street=$row['rue'];
64 $this->cp=$row['code_postal'];
65 $this->country=$row['pays'];
66 $this->vat_number=$row['tva_num'];
67
68 }
69 /*!
70 * \brief Get all the info for making a vat listing
71 * for the vat administration
72 *
73 * \param $p_year
74 *
75 * \return double array structure is
76 * ( j_poste,name,vat_number,amount,tva,customer(object)
77 *
78 */
79 function VatListing($p_year)
80 {
81 $cond_sql=" and A.j_date = B.j_date and extract(year from A.j_date) ='$p_year'";
82 /* List of customer */
83 $aCustomer=$this->cn->get_array('select f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
84 " where tva_num !='' ");
85
86 /* Use the code */
87
88 // BASE ACCOUNT
89 // for belgium
90 $s=new Acc_Parm_Code($this->cn,'VENTE');
91 $s->load();
92 $SOLD=$s->p_value;
93
94 $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
95 $c->load();
96 $CUSTOMER=$c->p_value;
97
98 $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
99 $t->load();
100 $TVA=$t->p_value;
101
102 $a_Res=array();
103 /* for each customer compute VAT, Amount...*/
104 foreach ($aCustomer as $l )
105 {
106 // Seek the customer
107 //---
108 $customer=$l['quick_code'];
109 $a_Res[$customer]['name']=$l['name'];
110 $a_Res[$customer]['vat_number']=$l['tva_num'];
111 $a_Res[$customer]['amount']=0;
112 $a_Res[$customer]['tva']=0;
113 $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
114 /* retrieve only operation of sold and vat */
115 // Get all the sell operation
116 //----
117 $sql="select distinct j_grpt
118 from
119 jrnx as A
120 join jrnx as B using (j_grpt)
121 where
122 A.j_qcode = '".$l['quick_code']."' and
123 B.j_poste::text like '".$SOLD."%'
124 $cond_sql
125 ";
126
127 $Res=$this->cn->exec_sql($sql);
128 // Foreach operation
129 // where 7% or tva account are involved
130 // and store the result in an array (a_Res)
131 //---
132
133 for ($i=0; $i < Database::num_row($Res);$i++)
134 {
135 // Get each row
136 //---
138
139
140 // select the operation
141 //----
142 $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=$1",[$row1['j_grpt']]);
144 if ($a_row==FALSE) $a_row=[];
145
146 // Store the amount in the array
147 //---
148 foreach ($a_row as $e)
149 {
150 $amount=0;
151 $tva=0;
152 if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
153 {
154 $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
155 }
156 if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
157 {
158 $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
159 }
160 // store sold
161 //---
162 $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
163 $a_Res[$customer]['amount']+=$amount;
164
165 // store vat
166 //---
167 $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
168 $a_Res[$customer]['tva']+=$tva;
169
170 // store customef info
171 //---
172 $a_Res[$customer]['customer']=$customer;
173 }
174 }// foreach $a
175 } // foreach ( customer)
176
177 return $a_Res;
178 }
179
180
181}
182
183?>
$input_from cn
Definition: balance.inc.php:66
$from_poste name
Manage the table parm_code which contains the custom parameter for the module accountancy.
class Customer are a specific kind of card
get_by_account($p_poste=0)
Get all info contains in the view thanks to the poste elt (account)
__construct($p_cn, $p_id=0)
Constructor /* only a db connection is needed.
VatListing($p_year)
Get all the info for making a vat listing for the vat administration.
static fetch_all($ret)
wrapper for the function pg_fetch_all
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
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
const FICHE_TYPE_CLIENT
Definition: constant.php:247
$Res