noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 */
44 function __construct($p_cn,$p_id=0)
45 {
46 $this->fiche_def_ref=FICHE_TYPE_CLIENT;
47 parent::__construct($p_cn,$p_id) ;
48
49 }
50 /*! \brief Get all info contains in the view
51 * thanks to the poste elt (account)
52 */
53 function get_by_account($p_poste=0)
54 {
55 $this->poste=($p_poste==0)?$this->poste:$p_poste;
56 $sql="select * from vw_client where poste_comptable=$1";
57 $Res=$this->cn->exec_sql($sql,array($this->poste));
58 if ( Database::num_row($Res) == 0) return null;
59 if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs fiches avec le même poste',1);
60 // There is only _one_ row by customer
62 $this->name=$row['name'];
63 $this->id=$row['f_id'];
64 $this->street=$row['rue'];
65 $this->cp=$row['code_postal'];
66 $this->country=$row['pays'];
67 $this->vat_number=$row['tva_num'];
68
69 }
70 /*!
71 * \brief Get all the info for making a vat listing
72 * for the vat administration
73 *
74 * \param $p_year
75 *
76 * \return double array structure is
77 * ( j_poste,name,vat_number,amount,tva,customer(object)
78 *
79 */
80 function VatListing($p_year)
81 {
82 $cond_sql=" and A.j_date = B.j_date and extract(year from A.j_date) ='$p_year'";
83 /* List of customer */
84 $aCustomer=$this->cn->get_array('select f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
85 " where tva_num !='' ");
86
87 /* Use the code */
88
89 // BASE ACCOUNT
90 // for belgium
91 $s=new Acc_Parm_Code($this->cn,'VENTE');
92 $s->load();
93 $SOLD=$s->p_value;
94
95 $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
96 $c->load();
97 $CUSTOMER=$c->p_value;
98
99 $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
100 $t->load();
101 $TVA=$t->p_value;
102
103 $a_Res=array();
104 /* for each customer compute VAT, Amount...*/
105 foreach ($aCustomer as $l )
106 {
107 // Seek the customer
108 //---
109 $customer=$l['quick_code'];
110 $a_Res[$customer]['name']=$l['name'];
111 $a_Res[$customer]['vat_number']=$l['tva_num'];
112 $a_Res[$customer]['amount']=0;
113 $a_Res[$customer]['tva']=0;
114 $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
115 /* retrieve only operation of sold and vat */
116 // Get all the sell operation
117 //----
118 $sql="select distinct j_grpt
119 from
120 jrnx as A
121 join jrnx as B using (j_grpt)
122 where
123 A.j_qcode = '".$l['quick_code']."' and
124 B.j_poste::text like '".$SOLD."%'
125 $cond_sql
126 ";
127
128 $Res=$this->cn->exec_sql($sql);
129 // Foreach operation
130 // where 7% or tva account are involved
131 // and store the result in an array (a_Res)
132 //---
133
134 for ($i=0; $i < Database::num_row($Res);$i++)
135 {
136 // Get each row
137 //---
139
140
141 // select the operation
142 //----
143 $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=$1",[$row1['j_grpt']]);
145 if ($a_row==FALSE) $a_row=[];
146
147 // Store the amount in the array
148 //---
149 foreach ($a_row as $e)
150 {
151 $amount=0;
152 $tva=0;
153 if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
154 {
155 $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
156 }
157 if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
158 {
159 $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
160 }
161 // store sold
162 //---
163 $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
164 $a_Res[$customer]['amount']+=$amount;
165
166 // store vat
167 //---
168 $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
169 $a_Res[$customer]['tva']+=$tva;
170
171 // store customef info
172 //---
173 $a_Res[$customer]['customer']=$customer;
174 }
175 }// foreach $a
176 } // foreach ( customer)
177
178 return $a_Res;
179 }
180
181
182}
183
184?>
$input_from cn
$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...
$t
Definition compute.php:46
$c
Definition compute.php:48
const FICHE_TYPE_CLIENT
Definition constant.php:247