altocompta/include/class_acc_ledger_info.php
Dany De Bontridder 82a1bf9bb8 Merged revisions 2868-2880 via svnmerge from
file:///home/developper/svn/phpcompta/branches/rel500

........
  r2869 | danydb | 2010-01-14 14:41:25 +0100 (Thu, 14 Jan 2010) | 1 line
  
  Bug :  fiche_attribut_synchro is really low, solution is to create 2 indexes
........
  r2874 | danydb | 2010-01-15 15:52:38 +0100 (Fri, 15 Jan 2010) | 3 lines
  
  The extra info are now available for ledger purchase, opportunity to clean
  code
........
  r2875 | danydb | 2010-01-15 19:51:33 +0100 (Fri, 15 Jan 2010) | 2 lines
  
  Fix bug : in rapport, the from doesn't work, the result is always 0
........
  r2876 | danydb | 2010-01-16 17:17:50 +0100 (Sat, 16 Jan 2010) | 1 line
  
  For Comptabilité->ACH and Comptabilité->VEN add shortcut to printing and customer/supplier
........
  r2877 | danydb | 2010-01-16 17:30:56 +0100 (Sat, 16 Jan 2010) | 2 lines
  
  Action : add search by type of documents
........
  r2878 | danydb | 2010-01-17 00:31:03 +0100 (Sun, 17 Jan 2010) | 1 line
  
  Fix bug : cannot choose a tva rate
........
  r2879 | danydb | 2010-01-20 22:37:11 +0100 (Wed, 20 Jan 2010) | 6 lines
  
  Action
  ======
  add a button for adding a card there is no filter on the category
  You can add whatever you want
........
  r2880 | danydb | 2010-01-21 16:10:57 +0100 (Thu, 21 Jan 2010) | 1 line
  
  Correct stylesheet : todo list 
........
2010-01-21 15:13:17 +00:00

182 lines
5.3 KiB
PHP

<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
require_once ('class_dossier.php');
require_once ('class_database.php');
require_once('ac_common.php');
/*!\file
* \brief Manage additional info for Accountancy
*/
/*!
* \brief Manage the additionnal info for operation (from jrn), when an invoice is generated,
* the order or other info are going to be stored and used in the detail.
* this class maps the table jrn_info
*/
class Acc_Ledger_Info {
var $cn; /*!< connection */
var $ji_id; /*!< primary key */
var $id_type; /*!< type id */
var $jr_id; /*!< primary key of the table jrn */
var $ji_value; /*!< value for this */
function __construct($p_cn,$p_ji_id=0) {
$this->cn=$p_cn;
$this->ji_id=$p_ji_id;
}
function insert() {
if ( ! isset ($this->jr_id) ||
! isset ($this->ji_value) ||
! isset ($this->id_type ) )
{
echo 'Appel incorrecte '.__FILE__.__LINE__;
var_dump($this);
exit();
}
try {
$sql=$this->cn->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
' returning ji_id ',
array ($this->jr_id,$this->id_type,$this->ji_value)
);
$this->ji_id=Database::fetch_result($sql,0,0);
} catch (Exception $e) {
echo "Echec sauvegarde info additionnelles";
throw $e;
}
}
function update() {
if ( ! isset ($this->jr_id) ||
! isset ($this->ji_value) ||
! isset ($this->jr_id ) )
{
echo 'Appel incorrecte '.__FILE__.__LINE__;
var_dump($this);
exit();
}
try {
$sql=$this->exec_sql('update jrn_info set jr_id=$1 ,id_type=$2,ji_value=$3 where ji_id=$4)'.
array ($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
);
} catch (Exception $e) {
$this->cn->rollback();
echo "Echec sauvegarde info additionnelles";
throw $e;
}
}
function load() {
$sql="select jr_id,id_type,ji_value from jrn_info where ji_id=".$this->ji_id;
$r=$this->cn->exec_sql($sql);
if (Database::num_row ($r) > 0 ) {
$this->from_array(Database::fetch_array($r,0));
return 0;
}else {
return 1;
}
}
function from_array($p_array) {
foreach ($p_array as $col=>$value) {
$this->$col=$value;
}
}
function set_id($p_ji_id) {
$this->$ji_id=$p_ji_id;
}
function set_jrn_id($p_id) {
$this->jr_id=$p_id;
}
function set_type($p_id) {
$this->id_type=$p_id;
}
function set_value($p_id) {
$this->ji_value=$p_id;
}
/*!\brief load all the jrn_info thanks the jr_id
* \return an array of object
*/
function load_all() {
if ( ! isset ($this->jr_id) ) { echo "jr_id is not set ".__FILE__.__LINE__;exit();}
$sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
$r=$this->cn->exec_sql($sql);
if (Database::num_row($r) == 0 )
return array();
$array=Database::fetch_all($r);
$ret=array();
foreach ($array as $row) {
$o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
$o->load();
$ret[]=clone $o;
}
return $ret;
}
function count() {
$sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
return $this->cn->count_sql($sql);
}
function search_id_internal($p_internal) {
$sql="select jr_id from jrn where jr_internal='$p_internal'";
$r=$this->cn->exec_sql($sql);
if (Database::num_row($r) > 0 ) {
$this->jr_id=Database::fetch_result($r,0,0);
return $this->jr_id;
} else {
$this->jr_id=-1;
return $this->jr_id;
}
}
/**
*@brief save all extra information in once, called by compta_ven and compta_ach
*@param $p_jr_id is the jrn.jr_id concerned,
*@param $p_array is the array with the data usually it is $_POST
*@note will change this->jr_id
*@see compta_ven.inc.php compta_ach.inc.php
*/
function save_extra($p_jr_id,$p_array) {
$this->jr_id=$p_jr_id;
if (strlen(trim($p_array['bon_comm'] )) != 0 ) {
$this->set_type('BON_COMMANDE');
$this->set_value($p_array['bon_comm']);
$this->insert();
}
if (strlen(trim($p_array['other_info'] )) != 0 ) {
$this->set_type('OTHER');
$this->set_value($p_array['other_info']);
$this->insert();
}
}
static function test_me() {
echo "Dossier = ".Dossier::id();
$cn=new Database(Dossier::id());
$a=new Acc_Ledger_Info($cn);
$a->jr_id=3;
$a->id_type='BON_COMMANDE';
$a->ji_value='BON';
var_dump($a);
$a->insert();
$a->set_jrn_id(7);
$a->set_type('OTHER');
$a->set_value('Autre test');
$a->insert();
}
}