';
@@ -255,8 +254,7 @@ echo '
Email
-
-
+
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index 01b733371..3bea3bfe1 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -1302,7 +1302,9 @@ function manage_search_filter(p_obj) {
* @see Acc_Ledger_Search
*/
function save_filter(p_div,p_dossier) {
- var elt=['ledger_type','nb_jrn','date_start','date_end','date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting'];
+ var elt=['ledger_type','nb_jrn','date_start','date_end',
+ 'date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting',
+ 'operation_filter'];
var eltValue={};
eltValue['gDossier']=p_dossier;
eltValue['op']="save_filter";
@@ -1326,8 +1328,6 @@ function save_filter(p_div,p_dossier) {
}
}
- //unpaid
- eltValue['unpaid']=$(p_div+"unpaid").checked;
new Ajax.Request('ajax_misc.php', {
method:"POST",
parameters:eltValue,
@@ -1365,7 +1365,8 @@ function load_filter(p_div,p_dossier,p_filter_id) {
try {
var answer=req.responseJSON;
console.log(answer);
- var elt=['ledger_type','date_start','date_end','date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting'];
+ var elt=['ledger_type','date_start','date_end','date_paid_start','date_paid_end',
+ 'desc','amount_min','amount_max','qcode','accounting','operation_filter'];
for (var i=0;ipost("date_paid_start", 'string', NULL));
$new->setp("date_paid_end", $http->post("date_paid_end", 'string', NULL));
$new->setp("ledger_type", $http->post("ledger_type", 'string'));
- $new->setp("unpaid", $http->post("unpaid", 'string', NULL));
+ $new->setp("operation_filter", $http->post("operation_filter", 'string', NULL));
$new->setp("filter_name", h($http->post("filter_name", 'string')));
$aJrn=[];
$max=$http->post("nb_jrn");
diff --git a/include/class/acc_account_ledger.class.php b/include/class/acc_account_ledger.class.php
index 8b2c146d4..e02e1881c 100644
--- a/include/class/acc_account_ledger.class.php
+++ b/include/class/acc_account_ledger.class.php
@@ -270,15 +270,7 @@ class Acc_Account_Ledger
return true;
}
- /*!\brief Get all the value for this object from the database
- * the data member are set
- * \return false if this account doesn't exist otherwise true
- */
- function get()
- {
- echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par Acc_Account_Ledger->load()";
- return $this->load();
- }
+
/*!
* \brief give the balance of an account
diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php
index 3e6f48d58..8bf4f5032 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -46,7 +46,6 @@ require_once NOALYSS_INCLUDE.'/lib/sort_table.class.php';
require_once NOALYSS_INCLUDE.'/database/jrn_def_sql.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_payment.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger_history.class.php';
-//require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_currency.class.php';
require_once NOALYSS_INCLUDE.'/database/operation_currency_sql.class.php';
@@ -65,7 +64,7 @@ class Acc_Ledger extends jrn_def_sql
var $id; /**< jrn_def.jrn_def_id */
var $db; /**< database connextion */
var $row; /**< row of the ledger */
- var $type; /**< type of the ledger ACH ODS FIN VEN or GL */
+ var $ledger_type; /**< type of the ledger ACH ODS FIN VEN or GL */
var $nb; /**< default number of rows by default 10 */
var $currency_id;
/**
@@ -80,7 +79,7 @@ class Acc_Ledger extends jrn_def_sql
$this->db=$p_cn;
$this->row=null;
$this->nb=MAX_ARTICLE;
- parent::__construct($p_cn, $p_id);
+ if ($p_id <> 0 ) parent::__construct($p_cn, $p_id);
}
/**
* retrieve currency_id from database
@@ -142,7 +141,7 @@ class Acc_Ledger extends jrn_def_sql
if ($this->id==0)
{
$this->ledger_name=_(" Tous les journaux");
- $this->type="GL";
+ $this->ledger_type="GL";
return "GL";
}
@@ -153,7 +152,7 @@ class Acc_Ledger extends jrn_def_sql
if ($Max==0)
return null;
$ret=Database::fetch_array($Res, 0);
- $this->type=$ret['jrn_def_type'];
+ $this->ledger_type=$ret['jrn_def_type'];
return $ret['jrn_def_type'];
}
@@ -469,6 +468,7 @@ class Acc_Ledger extends jrn_def_sql
*/
function get_solde($p_from, $p_to)
{
+ bcscale(4);
$ledger="";
if ($this->id!=0)
{
@@ -488,9 +488,9 @@ class Acc_Ledger extends jrn_def_sql
{
if ($line['deb']=='t')
- $deb+=$line['montant'];
+ $deb=bcadd($deb,$line['montant']);
else
- $cred+=$line['montant'];
+ $cred=bcadd($cred,$line['montant']);
}
$response=array($deb, $cred);
return $response;
@@ -588,7 +588,7 @@ class Acc_Ledger extends jrn_def_sql
$http=new HttpInput();
$msg=array();
if (!$p_readonly)
- $msg=$this->verify($p_array);
+ $msg=$this->verify_operation($p_array);
$this->id=$p_array['p_jrn'];
if (empty($p_array))
return _("Aucun résultat");
@@ -1513,14 +1513,6 @@ class Acc_Ledger extends jrn_def_sql
return true;
}
- /**
- * @brief get all the data from request and build the object
- */
- function get_request()
- {
- $this->id=$_REQUEST['p_jrn'];
- }
-
/**
* @brief retrieve the next number for this type of ledger
* @param p_cn connx
@@ -1954,18 +1946,30 @@ class Acc_Ledger extends jrn_def_sql
*/
public function existing_vat()
{
- if ($this->type=='ACH')
+ $array=[];
+ if ($this->get_type()=='ACH')
{
- $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ".
- " and exists (select qp_vat_code from quant_purchase
- where qp_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id",
+ $array=$this->db->get_array("select tva_id,tva_label,tva_poste
+ from tva_rate
+ where tva_rate != 0.0000
+ and exists (select qp_vat_code from quant_purchase
+ where
+ qp_vat_code=tva_id
+ and exists (select j_id
+ from jrnx where j_jrn_def = $1))
+ order by tva_id",
array($this->id));
}
- if ($this->type=='VEN')
+ if ($this->get_type()=='VEN')
{
- $array=$this->db->get_array("select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 ".
- " and exists (select qs_vat_code from quant_sold
- where qs_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id",
+ $array=$this->db->get_array("select tva_id,tva_label,tva_poste
+ from tva_rate
+ where tva_rate != 0.0000
+ and exists (select qs_vat_code from quant_sold
+ where qs_vat_code=tva_id
+ and
+ exists (select j_id from jrnx where j_jrn_def = $1))
+ order by tva_id",
array($this->id));
}
return $array;
@@ -1989,7 +1993,7 @@ class Acc_Ledger extends jrn_def_sql
*/
function get_other_amount($p_jr_id)
{
- if ($this->type=='ACH')
+ if ($this->get_type()=='ACH')
{
$array=$this->db->get_array('select sum(qp_price) as price,sum(qp_vat) as vat '.
',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv'.
@@ -1999,7 +2003,7 @@ class Acc_Ledger extends jrn_def_sql
where j_grpt=$1 ', array($p_jr_id));
$ret=$array[0];
}
- if ($this->type=='VEN')
+ if ($this->get_type()=='VEN')
{
$array=$this->db->get_array('select sum(qs_price) as price,sum(qs_vat) as vat '.
',0 as priv'.
@@ -2025,14 +2029,14 @@ class Acc_Ledger extends jrn_def_sql
*/
function vat_operation($p_jr_id)
{
- if ($this->type=='ACH')
+ if ($this->get_type()=='ACH')
{
$array=$this->db->get_array('select coalesce(sum(qp_vat),0) as sum_vat,tva_id
from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
array($p_jr_id));
}
- if ($this->type=='VEN')
+ if ($this->get_type()=='VEN')
{
$array=$this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id
from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
@@ -2084,7 +2088,7 @@ class Acc_Ledger extends jrn_def_sql
$max_date=$periode_max->first_day();
bcscale(2);
// min periode
- if ($this->type=='ACH')
+ if ($this->get_type()=='ACH')
{
/* get all amount exclude vat */
$sql="select coalesce(sum(qp_price),0) as price".
@@ -2102,14 +2106,18 @@ class Acc_Ledger extends jrn_def_sql
$ret=$array[0];
/* retrieve all vat code */
$array=$this->db->get_array("select coalesce(sum(qp_vat),0) as sum_vat,tva_id
- from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
- where tva_rate !=0 and j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
+ from quant_purchase as p
+ right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
+ where
+ tva_rate !=0
+ and j_date >= to_date($1,'DD.MM.YYYY')
+ and j_date < to_date($2,'DD.MM.YYYY')
and j_jrn_def = $3
group by tva_id",
array($min_date, $max_date, $this->id));
$ret['tva']=$array;
}
- if ($this->type=='VEN')
+ if ($this->get_type()=='VEN')
{
/* get all amount exclude vat */
$sql="select coalesce(sum(qs_price),0) as price".
@@ -2117,7 +2125,7 @@ class Acc_Ledger extends jrn_def_sql
',0 as priv'.
',0 as tva_nd'.
',coalesce(sum(qs_vat_sided),0) as reversed'.
- ',coalesce(sum(qs_vat_sided),0) as tva_np'.
+ ',0 as tva_np'.
' from quant_sold join jrnx using(j_id) '.
" where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
' and j_jrn_def = $3';
@@ -2126,25 +2134,38 @@ class Acc_Ledger extends jrn_def_sql
$ret=$array[0];
/* retrieve all vat code */
$array=$this->db->get_array("select coalesce(sum(qs_vat),0) as sum_vat,tva_id
- from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
- where tva_rate !=0 and
- j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
- and j_jrn_def = $3
+ from quant_sold as p
+ right join tva_rate on (qs_vat_code=tva_id)
+ join jrnx using(j_id)
+ where
+ tva_rate !=0 and
+ j_date >= to_date($1,'DD.MM.YYYY')
+ and j_date < to_date($2,'DD.MM.YYYY')
+ and j_jrn_def = $3
group by tva_id",
array($min_date, $max_date, $this->id));
$ret['tva']=$array;
}
- if ($this->type=="FIN")
+ if ($this->get_type()=="FIN")
{
/* find the quick code of this ledger */
$ledger=new Acc_Ledger_Fin($this->db, $this->id);
$qcode=$ledger->get_bank();
$bank_card=new Fiche($this->db, $qcode);
-
+ $periode=new Periode($this->db);
+ //$periode->find_periode($min_date);
+ //$a_date=$periode->get_limit($periode->get_exercice());
+
/* add the amount from Opening Writing */
- $cond=sprintf(" j_jrn_def <> %d and j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ",
- $this->id, $min_date, $max_date);
+ if ( $min_date <> $max_date)
+ {
+ $cond=sprintf("j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ",
+ $min_date,$max_date);
+ }else{
+ $cond=sprintf("j_date = to_date('%s','DD.MM.YYYY') ",
+ $min_date);
+ }
$saldo=$bank_card->get_bk_balance($cond);
$ret['amount']=bcsub($saldo['debit'], $saldo['credit']);
}
diff --git a/include/class/acc_ledger_fin.class.php b/include/class/acc_ledger_fin.class.php
index 819e5c43f..65a5766e9 100644
--- a/include/class/acc_ledger_fin.class.php
+++ b/include/class/acc_ledger_fin.class.php
@@ -42,7 +42,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
function __construct($p_cn, $p_init)
{
parent::__construct($p_cn, $p_init);
- $this->type = 'FIN';
+ $this->ledger_type = 'FIN';
}
/**
diff --git a/include/class/acc_ledger_history.class.php b/include/class/acc_ledger_history.class.php
index 3eaf2a64d..4d3a5a383 100644
--- a/include/class/acc_ledger_history.class.php
+++ b/include/class/acc_ledger_history.class.php
@@ -41,6 +41,8 @@ abstract class Acc_Ledger_History
protected $ma_ledger; //!< Array of ledger id : jrn_def.jrn_def_id
protected $m_mode; //!< mode of export L : one line, E accounting writing , D : Detail
public $db; //!< database connx
+ protected $ledger_type; //! type of ledger VEN , ACH , ODS, FIN
+ protected $filter_operation; //!< to filter paid, unpaid or all operation
/**
*
@@ -61,6 +63,7 @@ abstract class Acc_Ledger_History
$this->m_from=$p_from;
$this->m_to=$p_to;
$this->m_mode=$p_mode;
+ $this->filter_operation='all';
}
/**
* setter / getter
@@ -70,7 +73,23 @@ abstract class Acc_Ledger_History
{
return $this->m_from;
}
- /**
+ public function get_ledger_type()
+ {
+ return $this->ledger_type;
+ }
+
+ public function set_ledger_type($ledger_type)
+ {
+ if (! in_array($ledger_type,['ACH','ODS','VEN','FIN'])) {
+ record_log('Acc_Ledger_History:set_ledger_type '.var_export($ledger_type,TRUE));
+ throw new Exception (_("Donnée invalide",EXC_PARAM_VALUE));
+ }
+
+ $this->ledger_type=$ledger_type;
+ return $this;
+ }
+
+ /**
* setter / getter
* @returns m_to (periode id)
*/
@@ -141,9 +160,10 @@ abstract class Acc_Ledger_History
* @param integer $p_from periode id
* @param integer $p_to periode id
* @param char $p_mode L (list operation) E (extended detail) A (accouting writing) D (Detailled VAT)
+ * @param $p_paid values are all means all operations, paid only paid operation, unpaid for only unpaid
* @return Acc_Ledger_History_Generic Acc_Ledger_History_Sale Acc_Ledger_History_Financial Acc_Ledger_History_Purchase
*/
- static function factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
+ static function factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode,$p_paid)
{
// For Accounting writing , we use Acc_Ledger_History
if ($p_mode=="A")
@@ -183,6 +203,7 @@ abstract class Acc_Ledger_History
case "ACH":
$ret=new Acc_Ledger_History_Purchase($cn, $pa_ledger, $p_from,
$p_to, $p_mode);
+ $ret->set_filter_operation($p_paid);
return $ret;
break;
case "FIN":
@@ -193,6 +214,7 @@ abstract class Acc_Ledger_History
case "VEN":
$ret=new Acc_Ledger_History_Sale($cn, $pa_ledger, $p_from,
$p_to, $p_mode);
+ $ret->set_filter_operation($p_paid);
return $ret;
break;
@@ -233,11 +255,17 @@ abstract class Acc_Ledger_History
switch ($p_jrn_type)
{
case 'VEN':
- $tiers=$this->db->get_value('select max(qs_client) from quant_sold join jrnx using (j_id) join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1',
+ $tiers=$this->db->get_value('select max(qs_client) '
+ . 'from quant_sold join jrnx using (j_id) '
+ . 'join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1',
array($jr_id));
break;
case 'ACH':
- $tiers=$this->db->get_value('select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1',
+ $tiers=$this->db->get_value('select max(qp_supplier) '
+ . ' from quant_purchase '
+ . ' join jrnx using (j_id) '
+ . ' join jrn on (jr_grpt_id=j_grpt) '
+ . ' where jrn.jr_id=$1',
array($jr_id));
break;
@@ -287,4 +315,49 @@ abstract class Acc_Ledger_History
abstract function export_html();
abstract function get_row($p_limit, $p_offset);
+
+ /**
+ * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter
+ * @return string SQL Clause
+ */
+ protected function build_filter_operation()
+ {
+ switch ( $this->get_filter_operation() )
+ {
+ case 'all':
+ $sql_filter="";
+ break;
+ case 'paid':
+ $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
+ break;
+ case 'unpaid':
+ $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
+ break;
+ default:
+ throw new Exception(_("Filtre invalide",5));
+
+ }
+ return $sql_filter;
+ }
+ /**
+ * Filter operation
+ */
+ function get_filter_operation()
+ {
+ return $this->filter_operation;
+ }
+ /**
+ * Filter operation ,
+ * @param string $filter_operation, valid : all, paid, unpaid
+ */
+
+ public function set_filter_operation($filter_operation)
+ {
+ if (in_array($filter_operation,['all','paid','unpaid']))
+ {
+ $this->filter_operation=$filter_operation;
+ return $this;
+ }
+ throw new Exception(_("Filter invalide ".$filter_operation),5);
+ }
}
diff --git a/include/class/acc_ledger_history_financial.class.php b/include/class/acc_ledger_history_financial.class.php
index a639f0f1c..93cdb7e33 100644
--- a/include/class/acc_ledger_history_financial.class.php
+++ b/include/class/acc_ledger_history_financial.class.php
@@ -29,7 +29,11 @@ require_once NOALYSS_INCLUDE."/class/acc_ledger_history.class.php";
class Acc_Ledger_History_Financial extends Acc_Ledger_History
{
-
+ function __construct(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
+ {
+ parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
+ $this->ledger_type='FIN';
+ }
/**
* @brief display the accounting
*/
diff --git a/include/class/acc_ledger_history_generic.class.php b/include/class/acc_ledger_history_generic.class.php
index 3a849f19d..87bbd498f 100644
--- a/include/class/acc_ledger_history_generic.class.php
+++ b/include/class/acc_ledger_history_generic.class.php
@@ -49,6 +49,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
{
parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
$this->data=[];
+ $this->ledger_type='ODS';
}
/**
diff --git a/include/class/acc_ledger_history_purchase.class.php b/include/class/acc_ledger_history_purchase.class.php
index c9b5d25fe..3629c9f14 100644
--- a/include/class/acc_ledger_history_purchase.class.php
+++ b/include/class/acc_ledger_history_purchase.class.php
@@ -34,14 +34,21 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History
{
private $data; //!< Contains rows from SQL
-
+
public function __construct(\Database $cn, $pa_ledger, $p_from, $p_to,
$p_mode)
{
parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
+ $this->filter_operation='all';
+ $this->ledger_type='ACH';
+ }
+ public function get_filter_operation()
+ {
+ return $this->filter_operation;
}
- /**
+
+ /**
* @brief display the accounting
*/
public function export_accounting_html()
@@ -115,7 +122,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History
'jr_tech_per');
$cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
-
+ $sql_filter=$this->build_filter_operation();
$ledger_list=join(",", $this->ma_ledger);
$sql="
with row_purchase as
@@ -149,6 +156,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History
jr_id,
jr_pj_number,
to_char(jr_date,'DD.MM.YYYY') as str_date,
+ to_char(jr_date,'DDMMYY') as str_date_short,
to_char(jr_date_paid,'DD.MM.YYYY') as str_date_paid,
jr_internal,
qp_supplier,
@@ -162,6 +170,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History
private_amount,
novat+vat-tva_sided as tvac,
n_text,
+ jr_grpt_id,
jrn.currency_id,
jrn.currency_rate,
jrn.currency_rate_ref,
@@ -177,6 +186,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History
left join currency as c on (c.id=jrn.currency_id)
where
jr_def_id in ({$ledger_list})
+ {$sql_filter}
and {$periode}
{$cond_limite}
order by jrn.jr_date, substring(jr_pj_number,'[0-9]+$')::numeric ";
@@ -200,7 +210,7 @@ class Acc_Ledger_History_Purchase extends Acc_Ledger_History
quant_purchase
where
qp_internal = $1
- group by qp_vat_code,qp_internal order by qp_vat_code");
+ group by qp_vat_code order by qp_vat_code");
}
$nb_row=count($this->data);
diff --git a/include/class/acc_ledger_history_sale.class.php b/include/class/acc_ledger_history_sale.class.php
index 721e9a07b..d4669a95b 100644
--- a/include/class/acc_ledger_history_sale.class.php
+++ b/include/class/acc_ledger_history_sale.class.php
@@ -33,11 +33,14 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
{
private $data; //!< Contains rows from SQL
-
+
+
public function __construct(\Database $cn, $pa_ledger, $p_from, $p_to,
$p_mode)
{
parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
+ $this->filter_operation='all';
+ $this->ledger_type='VEN';
}
/**
* Display the operation of sales with detailled VAT
@@ -103,6 +106,7 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
");
}
}
+
/**
* Get the rows from jrnx and quant* tables
* @param int $p_limit max of rows to returns
@@ -114,7 +118,9 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
'jr_tech_per');
$cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
-
+
+ $sql_filter=$this->build_filter_operation();
+
$ledger_list=join(",", $this->ma_ledger);
$sql="
with row_sale as
@@ -154,6 +160,8 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
tva_sided,
novat,
novat+vat-tva_sided as tvac,
+ to_char(jr_date,'DDMMYY') as str_date_short,
+ jr_grpt_id,
jrn.currency_id,
jrn.currency_rate,
jrn.currency_rate_ref,
@@ -168,6 +176,7 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
left join currency as c on (c.id=jrn.currency_id)
where
jr_def_id in ({$ledger_list})
+ {$sql_filter}
and {$periode}
{$cond_limite}
order by jr_date, substring(jr_pj_number,'[0-9]+$')::numeric ";
@@ -190,7 +199,7 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
quant_sold
where
qs_internal = $1
- group by qs_vat_code,qs_internal order by qs_vat_code");
+ group by qs_vat_code order by qs_vat_code");
}
diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php
index 9475b3203..91446a164 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -51,7 +51,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
{
function __construct ($p_cn,$p_init)
{
- $this->type='ACH';
+ $this->ledger_type='ACH';
parent::__construct($p_cn,$p_init);
}
/*!\brief verify that the data are correct before inserting or confirming
@@ -560,7 +560,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
for ($i=0;$i< $nb_item;$i++)
{
$n_both=0;
- if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
+ if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
/* First we save all the items without vat */
$fiche=new Fiche($this->db);
@@ -1962,14 +1962,26 @@ EOF;
* @param $p_end jrn.jr_tech_per to
* @return handle to database result
*/
- function get_detail_purchase($p_from,$p_end)
+ function get_detail_purchase($p_from,$p_end,$p_filter_operation='all')
{
global $g_user;
// Journal valide
if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
-
- // Securite
- if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
+ switch ( $p_filter_operation)
+ {
+ case 'all':
+ $sql_filter="";
+ break;
+ case 'paid':
+ $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
+ break;
+ case 'unpaid':
+ $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
+ break;
+ default:
+ throw new Exception(_("Filtre invalide",5));
+
+ }
// get the data from the view
$sql = "select *
@@ -1977,6 +1989,7 @@ EOF;
where
jr_def_id = $1
and jr_date >= (select p_start from parm_periode where p_id = $2)
+ {$sql_filter}
and jr_date <= (select p_end from parm_periode where p_id = $3) "
.' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
$ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
diff --git a/include/class/acc_ledger_search.class.php b/include/class/acc_ledger_search.class.php
index f9891a153..9ffc29292 100644
--- a/include/class/acc_ledger_search.class.php
+++ b/include/class/acc_ledger_search.class.php
@@ -204,15 +204,23 @@ class Acc_Ledger_Search
$f_accounting->set_attribute('account', $this->div.'accounting');
$info=Icon_Action::infobulle(13);
- $f_paid=new ICheckbox('unpaid', null, $this->div.'unpaid');
- $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false;
+ // Status of the operation : paid, unpaid or all
+ $f_paid=new ISelect('operation_filter', null, $this->div.'operation_filter');
+ $f_paid->value=array(["value"=>'all',"label"=>_("Toutes")],
+ ["value"=>'unpaid',"label"=>_("Non payées")],
+ ["value"=>'paid',"label"=>_("Payées")]
+ );
+ $f_paid->selected=$http->request("operation_filter","string","all");
$r.=dossier::hidden();
$r.=HtmlInput::hidden('ledger_type', $this->type,
$this->div."ledger_type");
- $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+ $r.=HtmlInput::hidden('ac', $http->request('ac'));
+
+ // to avoid to find a given operation
if (isset($_REQUEST['hide_operation']))
- $r.=HtmlInput::hidden("hide_operation", $_REQUEST['hide_operation']);
+ $r.=HtmlInput::hidden("hide_operation", $http->request('hide_operation'));
+
ob_start();
$search_filter=$this->build_search_filter();
require_once NOALYSS_TEMPLATE.'/ledger_search.php';
@@ -526,12 +534,26 @@ class Acc_Ledger_Search
$and=" and ";
}
- // Only the unpaid
- if (isset($unpaid))
- {
- $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
- $and=" and ";
+ // Only the unpaid, paid or all
+ if ( isset($operation_filter)) {
+ switch ($operation_filter) {
+ case "unpaid":
+ $fil_paid=$and."(jr_rapt is null or jr_rapt = '') and jr_valid = true ";
+ $and=" and ";
+ break;
+ case "all":
+ $fil_paid="";
+ break;
+ case "paid":
+ $fil_paid=$and."(jr_rapt is not null or jr_rapt = 'paid') and jr_valid = true ";
+ $and=" and ";
+ break;
+ default:
+ throw new Exception(_("ALS01 Etat inconnu"),10);
+
+ }
}
+ // Operations which must not be seen in the result
if ( isset ($hide_operation) && trim($hide_operation) !="")
{
$fil_hide_operation=$and.sprintf( ' jr_id not in (%s)',sql_string($hide_operation));
diff --git a/include/class/acc_ledger_sold.class.php b/include/class/acc_ledger_sold.class.php
index 3d1e2ef20..eeb0fcbd7 100644
--- a/include/class/acc_ledger_sold.class.php
+++ b/include/class/acc_ledger_sold.class.php
@@ -53,7 +53,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
function __construct($p_cn, $p_init) {
parent::__construct($p_cn, $p_init);
- $this->type = 'VEN';
+ $this->ledger_type = 'VEN';
}
/*!\brief verify that the data are correct before inserting or confirming
@@ -300,8 +300,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
/* Save all the items without vat */
for ($i = 0; $i < $nb_item; $i++) {
$n_both = 0;
- if (strlen(trim(${'e_march' . $i})) == 0)
- continue;
+ if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
/* First we save all the items without vat */
$fiche = new Fiche($this->db);
@@ -1514,13 +1513,15 @@ EOF;
return $r;
}
/**
- * Retrieve data from the view v_detail_sale
+ * Retrieve data from the view v_detail_sale , gives all the row of an operation
+ *
* @remark $g_user connected user
* @param $p_from jrn.jr_tech_per from
* @param type $p_end jrn.jr_tech_per to
+ * @param $p_filter_operation valid option : all, paid, unpaid
* @return type
*/
- function get_detail_sale($p_from,$p_end)
+ function get_detail_sale($p_from,$p_end,$p_filter_operation='all')
{
global $g_user;
// Journal valide
@@ -1529,12 +1530,28 @@ EOF;
// Securite
if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
+ switch ( $p_filter_operation)
+ {
+ case 'all':
+ $sql_filter="";
+ break;
+ case 'paid':
+ $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
+ break;
+ case 'unpaid':
+ $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
+ break;
+ default:
+ throw new Exception(_("Filtre invalide",5));
+
+ }
// get the data from the view
$sql = "select *
from v_detail_sale
where
jr_def_id = $1
and jr_date >= (select p_start from parm_periode where p_id = $2)
+ {$sql_filter}
and jr_date <= (select p_end from parm_periode where p_id = $3) "
.' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
$ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
diff --git a/include/class/document_export.class.php b/include/class/document_export.class.php
index f491ab11a..66d5382d0 100644
--- a/include/class/document_export.class.php
+++ b/include/class/document_export.class.php
@@ -38,8 +38,8 @@ class Document_Export
// Create 2 temporary folders 1. convert to PDF + stamp
// 2. store result
$this->feedback = array();
- $this->store_convert = tempnam(sys_get_temp_dir(), 'convert_');
- $this->store_pdf = tempnam(sys_get_temp_dir(), 'pdf_');
+ $this->store_convert = tempnam($_ENV['TMP'], 'convert_');
+ $this->store_pdf = tempnam($_ENV['TMP'], 'pdf_');
unlink($this->store_convert);
unlink($this->store_pdf);
umask(0);
@@ -277,7 +277,7 @@ class Document_Export
$progress->set_value(100);
// remove files from "conversion folder"
- $this->clean_folder();
+ // $this->clean_folder();
}
/**
diff --git a/include/class/pdf.class.php b/include/class/pdf.class.php
index bc13ffd24..6f059e95f 100644
--- a/include/class/pdf.class.php
+++ b/include/class/pdf.class.php
@@ -140,6 +140,15 @@ class PDF extends PDF_Core
return array($customer_qc,$customer_name,$bank_qc,$bank_name);
}
}
-
+
+ public function set_filter_operation($filter_operation)
+ {
+ if (in_array($filter_operation, ['all', 'paid', 'unpaid']))
+ {
+ $this->filter_operation=$filter_operation;
+ return $this;
+ }
+ throw new Exception(_("Filter invalide ".$filter_operation), 5);
+ }
}
\ No newline at end of file
diff --git a/include/class/print_ledger.class.php b/include/class/print_ledger.class.php
index dfa59103b..8b8213ff6 100644
--- a/include/class/print_ledger.class.php
+++ b/include/class/print_ledger.class.php
@@ -24,137 +24,120 @@
* @author danydb
*/
require_once NOALYSS_INCLUDE.'/class/database.class.php';
-require_once NOALYSS_INCLUDE.'/class/print_ledger_detail.class.php';
-require_once NOALYSS_INCLUDE.'/class/print_ledger_simple.class.php';
-require_once NOALYSS_INCLUDE.'/class/print_ledger_simple_without_vat.class.php';
-require_once NOALYSS_INCLUDE.'/class/print_ledger_fin.class.php';
-require_once NOALYSS_INCLUDE.'/class/print_ledger_misc.class.php';
-require_once NOALYSS_INCLUDE.'/class/print_ledger_detail_item.class.php';
+require_once NOALYSS_INCLUDE.'/class/pdf.class.php';
/**
* @brief Strategie class for the print_ledger class
*
- */
-class Print_Ledger {
+*/
+class Print_Ledger extends PDF
+{
+ protected $filter_operation; // See Acc_Ledger_History::filter_operation
+ private $ledger ; //!< concerned Ledger
+ private $from ; //! integer parm_periode.p_id , start periode;
+ private $to ; //! integer parm_periode.p_id , end periode;
+ public function __construct(\Database $p_cn,
+ $orientation,
+ $unit,
+ $format,
+ Acc_Ledger $p_ledger,
+ $p_from,
+ $p_to,
+ $p_filter_operation)
+ {
+ parent::__construct($p_cn, $orientation, $unit, $format);
+ $this->ledger=$p_ledger;
+ $this->from=$p_from;
+ $this->to=$p_to;
+ $this->set_filter_operation($p_filter_operation);
+ }
+ public function get_ledger()
+ {
+ return $this->ledger;
+ }
+ public function get_from()
+ {
+ return $this->from;
+ }
+
+ public function get_to()
+ {
+ return $this->to;
+ }
+
+ public function set_ledger($ledger)
+ {
+ $this->ledger=$ledger;
+ return $this;
+ }
+
+ public function set_from($from)
+ {
+ $this->from=$from;
+ return $this;
+ }
+
+ public function set_to($to)
+ {
+ $this->to=$to;
+ return $this;
+ }
+ function get_filter_operation()
+ {
+ return $this->filter_operation;
+ }
+ /**
+ * Filter the operations ,
+ * @param string $filter_operation : all , paid, unpaid
+ * @return $this
+ * @throws Exception 5 , if filter invalid
+ */
+ public function set_filter_operation($filter_operation)
+ {
+ if (in_array($filter_operation,['all','paid','unpaid']))
+ {
+ $this->filter_operation=$filter_operation;
+ return $this;
+ }
+ throw new Exception(_("Filter invalide ".$filter_operation),5);
+ }
/**
* Create an object Print_Ledger* depending on $p_type_export ( 0 => accounting
* 1-> one row per operation 2-> detail of item)
- * @param type $cn
- * @param type $p_type_export
- * @param type $p_format_output CSV or PDF
+ * @param Database $cn
+ * @param char $p_type_export E(xtended) L(isting) A(ccounting) D(etail)
* @param Acc_Ledger $ledger
*/
- static function factory(Database $cn, $p_type_export, $p_format_output, Acc_Ledger $p_ledger) {
+ static function factory(Database $cn, $p_type_export, Acc_Ledger $p_ledger,$p_from,$p_to,$p_filter_operation)
+ {
+ /**
+ * @Bug
+ * Strange PHP Bug when autoloader is not used , the require_once doesn't seems to
+ * work properly and does not include the files , except if you put them here
+ *
+ * if you put them on the top of this file, export_ledger_pdf.php will include the files
+ * but not export_ledger_csv.php
+ */
+ require_once NOALYSS_INCLUDE.'/class/print_ledger_detail.class.php';
+ require_once NOALYSS_INCLUDE.'/class/print_ledger_simple.class.php';
+ require_once NOALYSS_INCLUDE.'/class/print_ledger_simple_without_vat.class.php';
+ require_once NOALYSS_INCLUDE.'/class/print_ledger_fin.class.php';
+ require_once NOALYSS_INCLUDE.'/class/print_ledger_misc.class.php';
+ require_once NOALYSS_INCLUDE.'/class/print_ledger_detail_item.class.php';
+
/**
* For PDF output
*/
- if ($p_format_output == 'PDF') {
- switch ($p_type_export) {
- case 'D':
- $own=new Noalyss_Parameter_Folder($cn);
- $jrn_type=$p_ledger->get_type();
- //---------------------------------------------
- // Detailled Printing (accounting )
- //---------------------------------------------
- if ($jrn_type=='ACH'||$jrn_type=='VEN')
- {
- if (
- ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
- ==0)||
- ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
- ==0)
- )
- {
- $pdf=new Print_Ledger_Simple_without_vat($cn,
- $p_ledger);
- $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
- return $pdf;
- }
- if ($own->MY_TVA_USE=='Y')
- {
- $pdf=new Print_Ledger_Simple($cn, $p_ledger);
- return $pdf;
- }
- if ($own->MY_TVA_USE=='N')
- {
- $pdf=new Print_Ledger_Simple_without_vat($cn,
- $p_ledger);
- return $pdf;
- }
- }
- elseif ($jrn_type=='FIN')
- {
- $pdf=new Print_Ledger_Financial($cn, $p_ledger);
- return $pdf;
- } else
- {
- return new Print_Ledger_Detail($cn, $p_ledger);
- }
- break;
-
- case 'L':
- //----------------------------------------------------------------------
- // Simple Printing Purchase Ledger
- //---------------------------------------------------------------------
- $own=new Noalyss_Parameter_Folder($cn);
- $jrn_type=$p_ledger->get_type();
-
-
- if ($jrn_type=='ACH'||$jrn_type=='VEN')
- {
- if (
- ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
- ==0)||
- ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
- ==0)
- )
- {
- $pdf=new Print_Ledger_Simple_without_vat($cn,
- $p_ledger);
- $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
- return $pdf;
- }
- if ($own->MY_TVA_USE=='Y')
- {
- $pdf=new Print_Ledger_Simple($cn, $p_ledger);
- return $pdf;
- }
- if ($own->MY_TVA_USE=='N')
- {
- $pdf=new Print_Ledger_Simple_without_vat($cn,
- $p_ledger);
- return $pdf;
- }
- }
-
- if ($jrn_type=='FIN')
- {
- $pdf=new Print_Ledger_Financial($cn, $p_ledger);
- return $pdf;
- }
- if ($jrn_type=='ODS'||$p_ledger->id==0)
- {
- $pdf=new Print_Ledger_Misc($cn, $p_ledger);
- return $pdf;
- }
- break;
- case 'E':
- /**********************************************************
- * Print Detail Operation + Item
- * ********************************************************* */
- $own=new Noalyss_Parameter_Folder($cn);
- $jrn_type=$p_ledger->get_type();
- if ($jrn_type=='FIN')
- {
- $pdf=new Print_Ledger_Detail($cn, $p_ledger);
- return $pdf;
- }
- if ($jrn_type=='ODS'||$p_ledger->id==0)
- {
- $pdf=new Print_Ledger_Detail($cn, $p_ledger);
- return $pdf;
- }
+ switch ($p_type_export) {
+ case 'D':
+ $own=new Noalyss_Parameter_Folder($cn);
+ $jrn_type=$p_ledger->get_type();
+ //---------------------------------------------
+ // Detailled Printing (accounting )
+ //---------------------------------------------
+ if ($jrn_type=='ACH'||$jrn_type=='VEN')
+ {
if (
($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
==0)||
@@ -162,21 +145,113 @@ class Print_Ledger {
==0)
)
{
- $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger);
- $pdf->set_error('Ce journal ne peut être imprimé en mode simple');
+ $pdf=new Print_Ledger_Simple_without_vat($cn,
+ $p_ledger,$p_from,$p_to,$p_filter_operation);
+ $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
return $pdf;
}
- $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger);
+ if ($own->MY_TVA_USE=='Y')
+ {
+ $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
+ return $pdf;
+ }
+ if ($own->MY_TVA_USE=='N')
+ {
+ $pdf=new Print_Ledger_Simple_without_vat($cn,
+ $p_ledger,$p_from,$p_to,$p_filter_operation);
+ return $pdf;
+ }
+ }
+ elseif ($jrn_type=='FIN')
+ {
+ $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to);
return $pdf;
- case 'A':
- /***********************************************************
- * Accounting
- */
- $pdf=new Print_Ledger_Detail($cn, $p_ledger);
+ } else
+ {
+ return new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
+ }
+ break;
+
+ case 'L':
+ //----------------------------------------------------------------------
+ // Simple Printing Purchase Ledger
+ //---------------------------------------------------------------------
+ $own=new Noalyss_Parameter_Folder($cn);
+ $jrn_type=$p_ledger->get_type();
+
+
+ if ($jrn_type=='ACH'||$jrn_type=='VEN')
+ {
+ if (
+ ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
+ ==0)||
+ ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
+ ==0)
+ )
+ {
+ $pdf=new Print_Ledger_Simple_without_vat($cn,
+ $p_ledger,$p_from,$p_to,$p_filter_operation);
+ $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
+ return $pdf;
+ }
+ if ($own->MY_TVA_USE=='Y')
+ {
+ $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
+ return $pdf;
+ }
+ if ($own->MY_TVA_USE=='N')
+ {
+ $pdf=new Print_Ledger_Simple_without_vat($cn,
+ $p_ledger,$p_from,$p_to,$p_filter_operation);
+ return $pdf;
+ }
+ }
+
+ if ($jrn_type=='FIN')
+ {
+ $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to);
return $pdf;
- break;
- } // end switch
- } // end $p_format == PDF
+ }
+ $pdf=new Print_Ledger_Misc($cn, $p_ledger,$p_from,$p_to);
+ return $pdf;
+ break;
+ case 'E':
+ /**********************************************************
+ * Print Detail Operation + Item
+ * ********************************************************* */
+ $own=new Noalyss_Parameter_Folder($cn);
+ $jrn_type=$p_ledger->get_type();
+ if ($jrn_type=='FIN')
+ {
+ $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
+ return $pdf;
+ }
+ if ($jrn_type=='ODS'||$p_ledger->id==0)
+ {
+ $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
+ return $pdf;
+ }
+ if (
+ ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
+ ==0)||
+ ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
+ ==0)
+ )
+ {
+ $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
+ $pdf->set_error('Ce journal ne peut être imprimé en mode simple');
+ return $pdf;
+ }
+ $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
+ return $pdf;
+ case 'A':
+ /***********************************************************
+ * Accounting
+ */
+ $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
+ return $pdf;
+ break;
+ } // end switch
}
// end function
@@ -206,7 +281,10 @@ class Print_Ledger {
and uj_priv in ('R','W')
and ( jrn_enable=1
or
- exists (select 1 from jrn where jr_def_id=jrn_def_id and jr_tech_per in (select p_id from parm_periode where p_exercice=$2)))
+ exists (select 1 from jrn
+ where
+ jr_def_id=jrn_def_id
+ and jr_tech_per in (select p_id from parm_periode where p_exercice=$2)))
order by jrn_def_name
";
$a_jrn=$cn->get_array($sql, array($g_user->login, $exercice));
@@ -216,8 +294,12 @@ class Print_Ledger {
$a_jrn=$cn->get_array("select jrn_def_id
from jrn_def join jrn_type on jrn_def_type=jrn_type_id
where
- jrn_enable=1 or exists(select 1 from jrn where jr_def_id=jrn_def_id and jr_tech_per in (select p_id from parm_periode where p_exercice=$1))
- order by jrn_def_name
+ jrn_enable=1
+ or exists(select 1 from jrn
+ where
+ jr_def_id=jrn_def_id
+ and jr_tech_per in (select p_id from parm_periode where p_exercice=$1))
+ order by jrn_def_name
", [$exercice]);
}
$a=[];
@@ -228,7 +310,28 @@ class Print_Ledger {
}
return $a;
}
-
+ /**
+ * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter
+ * @return string SQL Clause
+ */
+ protected function build_filter_operation()
+ {
+ switch ($this->get_filter_operation())
+ {
+ case 'all':
+ $sql_filter="";
+ break;
+ case 'paid':
+ $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
+ break;
+ case 'unpaid':
+ $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
+ break;
+ default:
+ throw new Exception(_("Filtre invalide", 5));
+ }
+ return $sql_filter;
+ }
}
?>
diff --git a/include/class/print_ledger_detail.class.php b/include/class/print_ledger_detail.class.php
index 2c59ecfb8..baa7e8fae 100644
--- a/include/class/print_ledger_detail.class.php
+++ b/include/class/print_ledger_detail.class.php
@@ -23,19 +23,16 @@
* \brief this class extends PDF and let you export the detailled printing
* of any ledgers
*/
-require_once NOALYSS_INCLUDE.'/class/pdf_land.class.php';
+require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
-class Print_Ledger_Detail extends PDF
+
+class Print_Ledger_Detail extends Print_Ledger
{
- public function __construct ($p_cn = null, Acc_Ledger $ledger)
+ public function __construct (Database $p_cn , Acc_Ledger $ledger,$p_from,$p_to)
{
- if($p_cn == null) die("No database connection. Abort.");
+ parent::__construct($p_cn,'L', 'mm', 'A4',$ledger,$p_from,$p_to,'all');
- parent::__construct($p_cn,'L', 'mm', 'A4');
- $this->ledger=$ledger;
- date_default_timezone_set ('Europe/Paris');
-
}
function setDossierInfo($dossier = "n/a")
@@ -73,7 +70,7 @@ class Print_Ledger_Detail extends PDF
$rap_deb=0;
$rap_cred=0;
// take all operations from jrn
- $array=$this->ledger->get_operation($_GET['from_periode'],$_GET['to_periode']);
+ $array=$this->get_ledger()->get_operation($this->get_from(),$this->get_to());
$this->SetFont('DejaVu','BI',7);
$this->write_cell(215,7,'report Débit',0,0,'R');
diff --git a/include/class/print_ledger_detail_item.class.php b/include/class/print_ledger_detail_item.class.php
index 745fea52b..c9fca66a3 100644
--- a/include/class/print_ledger_detail_item.class.php
+++ b/include/class/print_ledger_detail_item.class.php
@@ -25,17 +25,14 @@
*/
require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php';
-require_once NOALYSS_INCLUDE.'/class/pdf_land.class.php';
+require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
-class Print_Ledger_Detail_Item extends PDFLand
+class Print_Ledger_Detail_Item extends Print_Ledger
{
- public function __construct (Database $p_cn,Acc_Ledger $p_jrn)
+ public function __construct (Database $p_cn,Acc_Ledger $p_jrn,$p_from,$p_to,$p_filter_operation)
{
- if($p_cn == null) die("No database connection. Abort.");
-
- parent::__construct($p_cn,'L', 'mm', 'A4');
- $this->ledger=$p_jrn;
+ parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation);
$this->show_col=true;
}
@@ -76,7 +73,7 @@ class Print_Ledger_Detail_Item extends PDFLand
{
$this->Ln(2);
$this->SetFont('Arial', 'I', 8);
- $this->Cell(50,8,' Journal '.$this->ledger->get_name(),0,0,'C');
+ $this->Cell(50,8,' Journal '.$this->get_ledger()->get_name(),0,0,'C');
//Arial italic 8
//Page number
$this->Cell(30,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L');
@@ -91,24 +88,25 @@ class Print_Ledger_Detail_Item extends PDFLand
function export()
{
bcscale(2);
- $jrn_type=$this->ledger->get_type();
- $http=new HttpInput();
+ $jrn_type=$this->get_ledger()->get_type();
+
switch ($jrn_type)
{
case 'VEN':
- $ledger=new Acc_Ledger_Sold($this->cn, $this->ledger->jrn_def_id);
- $ret_detail=$ledger->get_detail_sale($http->get('from_periode','number'),$http->get('to_periode','number'));
+ $ledger=new Acc_Ledger_Sold($this->cn, $this->get_ledger()->jrn_def_id);
+ $ret_detail=$ledger->get_detail_sale($this->get_from(),$this->get_to(), $this->filter_operation);
break;
case 'ACH':
- $ledger=new Acc_Ledger_Purchase($this->cn, $this->ledger->jrn_def_id);
- $ret_detail=$ledger->get_detail_purchase($http->get('from_periode','number'),$http->get('to_periode','number'));
+ $ledger=new Acc_Ledger_Purchase($this->cn, $this->get_ledger()->jrn_def_id);
+ $ret_detail=$ledger->get_detail_purchase($this->get_from(),$this->get_to(),$this->filter_operation);
break;
default:
die (__FILE__.":".__LINE__.'Journal invalide');
break;
}
if ( $ret_detail == null ) return;
- $prepared_query=new Prepared_Query($this->ledger->db);
+
+ $prepared_query=new Prepared_Query($this->cn);
$prepared_query->prepare_reconcile_date();
$nb=Database::num_row($ret_detail);
@@ -138,7 +136,7 @@ class Print_Ledger_Detail_Item extends PDFLand
$this->line_new(6);
// Payment info
// Prepare the query for reconcile date
- $ret_reconcile=$this->ledger->db->execute('reconcile_date', array($row['jr_id']));
+ $ret_reconcile=$this->cn->execute('reconcile_date', array($row['jr_id']));
$max=Database::num_row($ret_reconcile);
for ($e=0; $e<$max; $e++)
{
diff --git a/include/class/print_ledger_fin.class.php b/include/class/print_ledger_fin.class.php
index f7562c97a..316e02e69 100644
--- a/include/class/print_ledger_fin.class.php
+++ b/include/class/print_ledger_fin.class.php
@@ -22,16 +22,16 @@
/*!\file
* \brief print a listing of financial
*/
-require_once NOALYSS_INCLUDE.'/class/pdf.class.php';
-class Print_Ledger_Financial extends PDF
+require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
+
+class Print_Ledger_Financial extends Print_Ledger
{
private $rap_amount; /* amount from begining exercice */
private $tp_amount; /* amount total page */
- function __construct($p_cn, Acc_Ledger $p_jrn)
+ function __construct(Database $p_cn, Acc_Ledger $p_jrn,$p_from,$p_to)
{
- parent::__construct($p_cn,'P','mm','A4');
- $this->ledger=$p_jrn;
+ parent::__construct($p_cn,'P','mm','A4',$p_jrn,$p_from,$p_to,'all');
$this->jrn_type=$p_jrn->get_type();
// report from begin exercice
@@ -40,7 +40,7 @@ class Print_Ledger_Financial extends PDF
// total page
$this->tp_amount=0;
- $amount=$this->ledger->previous_amount($_GET['from_periode']);
+ $amount=$this->get_ledger()->previous_amount($this->get_from());
$this->rap_amount=$amount['amount'];
}
function Header()
@@ -118,7 +118,7 @@ class Print_Ledger_Financial extends PDF
$this->write_cell(10,5,$row['date_fmt']);
$this->write_cell(10,5,$row['internal']);
- $name=$this->ledger->get_tiers($this->jrn_type,$row['id']);
+ $name=$ledger->get_tiers($this->jrn_type,$row['id']);
$this->write_cell(40,5,$name,0,0,'L');
$this->LongLine(60,5,$row['comment'],0,'L');
diff --git a/include/class/print_ledger_misc.class.php b/include/class/print_ledger_misc.class.php
index c5f38ee26..60404055c 100644
--- a/include/class/print_ledger_misc.class.php
+++ b/include/class/print_ledger_misc.class.php
@@ -22,14 +22,13 @@
/*!\file
* \brief print a listing of financial
*/
-require_once NOALYSS_INCLUDE.'/class/pdf.class.php';
-class Print_Ledger_Misc extends PDF
+require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
+
+class Print_Ledger_Misc extends Print_Ledger
{
- function __construct($p_cn,$p_jrn)
+ function __construct(Database $p_cn,$p_jrn,$p_from,$p_to)
{
- parent::__construct($p_cn,'P','mm','A4');
- $this->ledger=$p_jrn;
- $this->jrn_type=$p_jrn->get_type();
+ parent::__construct($p_cn,'P','mm','A4',$p_jrn,$p_from,$p_to,"all");
}
function Header()
{
@@ -77,6 +76,7 @@ class Print_Ledger_Misc extends PDF
$http->get('to_periode','number'));
$this->SetFont('DejaVu', '', 6);
if ( $a_jrn == null ) return;
+ $ledger=$this->get_ledger();
for ( $i=0;$iLongLine(30,5,$row['jr_pj_number']);
$this->write_cell(20,5,$row['jr_internal']);
$type=$this->cn->get_value("select jrn_def_type from jrn_def where jrn_def_id=$1",array($a_jrn[$i]['jr_def_id']));
- $other=mb_substr($this->ledger->get_tiers($type,$a_jrn[$i]['jr_id']),0,25);
+ $other=mb_substr($ledger->get_tiers($type,$a_jrn[$i]['jr_id']),0,25);
$this->LongLine(25,5,$other,0,'L');
$positive=$row['montant'];
$this->LongLine(60,5,$row['comment'],0,'L');
diff --git a/include/class/print_ledger_simple.class.php b/include/class/print_ledger_simple.class.php
index 8c8a3cb45..7d8265d37 100644
--- a/include/class/print_ledger_simple.class.php
+++ b/include/class/print_ledger_simple.class.php
@@ -23,20 +23,17 @@
* \brief this class extends PDF and let you export the detailled printing
* of any ledgers
*/
-require_once NOALYSS_INCLUDE.'/class/pdf.class.php';
+require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
-class Print_Ledger_Simple extends PDF
+class Print_Ledger_Simple extends \Print_Ledger
{
- public function __construct ($p_cn, Acc_Ledger $p_jrn)
+ public function __construct ($p_cn, Acc_Ledger $p_jrn,$p_from,$p_to,$p_filter_operation)
{
- $http=new HttpInput();
- if($p_cn == null) die("No database connection. Abort.");
-
- parent::__construct($p_cn,'L', 'mm', 'A4');
- $this->ledger=$p_jrn;
- $this->a_Tva=$this->ledger->existing_vat();
+ parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation);
+
+ $this->a_Tva=$this->get_ledger()->existing_vat();
foreach($this->a_Tva as $line_tva)
{
//initialize Amount TVA
@@ -50,8 +47,8 @@ class Print_Ledger_Simple extends PDF
* get rappel to initialize amount rap_xx
*the easiest way is to compute sum from quant_
*/
- $from_periode=$http->get('from_periode',"number");
- $this->previous=$this->ledger->previous_amount($from_periode);
+ $from_periode=$this->get_from();
+ $this->previous=$this->get_ledger()->previous_amount($from_periode);
/* initialize the amount to report */
foreach($this->previous['tva'] as $line_tva)
@@ -123,7 +120,10 @@ class Print_Ledger_Simple extends PDF
$this->SetFont('DejaVu','',6);
// page Header
- $this->Cell(143,6,'report',0,0,'R');
+ if ( ! $flag_tva)
+ $this->Cell(143,6,'report',0,0,'R');
+ else
+ $this->Cell(78,6,'report',0,0,'R');
$this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
if ( $this->jrn_type != 'VEN')
{
@@ -157,7 +157,12 @@ class Print_Ledger_Simple extends PDF
//Position at 3 cm from bottom
$this->SetY(-20);
/* write reporting */
- $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */
+ $flag_tva=(count($this->a_Tva) > 4)?true:false;
+ if ( ! $flag_tva)
+ $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */
+ else
+ $this->Cell(78,6,'Total page ','T',0,'R'); /* HTVA */
+
$this->Cell(15,6,nbm($this->tp_htva),'T',0,'R'); /* HTVA */
if ( $this->jrn_type !='VEN')
{
@@ -173,8 +178,13 @@ class Print_Ledger_Simple extends PDF
$this->Cell(15,6,nbm($this->tp_tvac),'T',0,'R'); /* Tvac */
$this->Ln(2);
-
- $this->Cell(143,6,'report',0,0,'R'); /* HTVA */
+ $flag_tva=(count($this->a_Tva) > 4)?true:false;
+
+ if ( ! $flag_tva)
+ $this->Cell(143,6,'report',0,0,'R');
+ else
+ $this->Cell(78,6,'report',0,0,'R');
+
$this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
if ( $this->jrn_type !='VEN')
{
@@ -205,16 +215,24 @@ class Print_Ledger_Simple extends PDF
*/
function export()
{
- bcscale(2);
- $http=new HttpInput();
+ bcscale(4);
+ $ledger=$this->get_ledger();
+ $ledger_history=Acc_Ledger_History::factory($this->cn,
+ array($ledger->id),
+ $this->get_from(),
+ $this->get_to(),
+ 'D',
+ $this->get_filter_operation());
+ $ledger_history->get_row();
+ $a_jrn=$ledger_history->get_data();
- $a_jrn=$this->ledger->get_operation($http->get('from_periode',"number"),
- $http->get('to_periode',"number"));
-
if ( $a_jrn == null ) return;
+ // Count the number of VAT cols
+ $flag_tva=(count($this->a_Tva) > 4)?true:false;
+
// Prepare the query for reconcile date
- $prepared_query=new Prepared_Query($this->ledger->db);
+ $prepared_query=new Prepared_Query($ledger->db);
$prepared_query->prepare_reconcile_date();
for ( $i=0;$iledger->vat_operation($a_jrn[$i]['jr_grpt_id']);
+ $aAmountVat=$ledger->vat_operation($a_jrn[$i]['jr_grpt_id']);
// put vat into array
for ($f=0;$fledger->db->execute('reconcile_date',array($row['id']));
- $this->LongLine(15,5,($row['pj']),0);
- $this->write_cell(10,5,$row['date_fmt'],0,0);
- $this->write_cell(13,5,$row['internal'],0,0);
- list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
+ $ret_reconcile=$ledger->db->execute('reconcile_date',array($row['jr_id']));
+ $this->LongLine(15,5,($row['jr_pj_number']),0);
+ $this->write_cell(10,5,$row['str_date_short'],0,0);
+ $this->write_cell(13,5,$row['jr_internal'],0,0);
+ list($qc,$name)=$this->get_tiers($row['jr_id'],$this->jrn_type);
$this->LongLine(40,5,"[".$qc."]".$name,0,'L');
- $this->LongLine(65,5,mb_substr($row['comment'],0,150),0,'L');
+ if ( !$flag_tva ) {
+ $this->LongLine(65,5,mb_substr($row['jr_comment'],0,150),0,'L');
+ }
/* get other amount (without vat, total vat included, private, ND */
- $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
+ $other=$ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
-
-
$this->write_cell(15,5,nbm($other['price']),0,0,'R');
- if ( $this->jrn_type !='VEN')
+
+ if ( $ledger_history->get_ledger_type() !='VEN')
{
$this->write_cell(15,5,nbm($other['priv']),0,0,'R');
$this->write_cell(15,5,nbm($other['tva_nd']),0,0,'R');
@@ -271,11 +290,11 @@ class Print_Ledger_Simple extends PDF
$l_tvac=bcadd($l_tvac,$other['tva_nd']);
$this->write_cell(15,5,nbm($l_tvac),0,0,'R');
$this->line_new(2);
- $this->write_cell(15,5, _("Payé par"));
// Add the payment information on another row
$max=Database::num_row($ret_reconcile);
$str_payment="";
if ($max > 0) {
+ $this->write_cell(15,5, _("Payé par"));
$sep="";
for ($e=0;$e<$max;$e++) {
$row=Database::fetch_array($ret_reconcile, $e);
diff --git a/include/class/print_ledger_simple_without_vat.class.php b/include/class/print_ledger_simple_without_vat.class.php
index 688638dc2..bbc3c5f92 100644
--- a/include/class/print_ledger_simple_without_vat.class.php
+++ b/include/class/print_ledger_simple_without_vat.class.php
@@ -23,17 +23,15 @@
* \brief this class extends PDF and let you export the detailled printing
* of any ledgers
*/
-require_once NOALYSS_INCLUDE.'/class/pdf.class.php';
+require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
-class Print_Ledger_Simple_Without_Vat extends PDF
+class Print_Ledger_Simple_Without_Vat extends Print_Ledger
{
- public function __construct ($p_cn,$p_jrn)
+ public function __construct ($p_cn,$p_jrn,$p_from,$p_to,$p_filter_operation)
{
- if($p_cn == null) die("No database connection. Abort.");
- parent::__construct($p_cn,'L', 'mm', 'A4');
- $this->ledger=$p_jrn;
+ parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation);
$this->jrn_type=$p_jrn->get_type();
//----------------------------------------------------------------------
/* report
@@ -41,14 +39,13 @@ class Print_Ledger_Simple_Without_Vat extends PDF
* get rappel to initialize amount rap_xx
*the easiest way is to compute sum from quant_
*/
- $this->previous=$this->ledger->previous_amount($_GET['from_periode']);
+ $this->previous=$this->get_ledger()->previous_amount($p_from);
$this->rap_htva=$this->previous['price'];
$this->rap_tvac=$this->previous['price'];
$this->rap_priv=$this->previous['priv'];
-
}
function setDossierInfo($dossier = "n/a")
@@ -141,43 +138,53 @@ class Print_Ledger_Simple_Without_Vat extends PDF
*/
function export()
{
- $http=new HttpInput;
- $a_jrn=$this->ledger->get_operation($http->get('from_periode','number'),$http->get('to_periode','number'));
-
- if ( $a_jrn == null ) return;
+
+ $ledger_history=Acc_Ledger_History::factory($this->cn,
+ array($this->get_ledger()->id),
+ $this->get_from(),
+ $this->get_to(),
+ 'D',
+ $this->get_filter_operation());
+
+ $ledger_history->get_row();
+ $a_jrn=$ledger_history->get_data();
+
+ if ( empty($a_jrn ) ) return;
// Prepare the query for reconcile date
$prepared_query=new Prepared_Query($this->cn);
$prepared_query->prepare_reconcile_date();
+ $ledger=$this->get_ledger();
+
for ( $i=0;$iLongLine(15,5,($row['pj']),0);
- $this->write_cell(15,5,$row['date_fmt'],0,0);
- $this->write_cell(20,5,$row['internal'],0,0);
- list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
+ $this->LongLine(15,5,($row['jr_pj_number']),0);
+ $this->write_cell(15,5,$row['str_date_short'],0,0);
+ $this->write_cell(20,5,$row['jr_internal'],0,0);
+ list($qc,$name)=$this->get_tiers($row['jr_id'],$this->jrn_type);
$this->write_cell(20,5,$qc,0,0);
$this->LongLine(40,5,$name,0,'L');
- $this->LongLine(105,5,$row['comment'],0,'L');
+ $this->LongLine(105,5,$row['jr_comment'],0,'L');
/* get other amount (without vat, total vat included, private, ND */
- $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
+ $other=$ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
$this->tp_htva+=$other['price'];
$this->tp_priv+=$other['priv'];
$this->rap_htva+=$other['price'];
$this->rap_priv+=$other['priv'];
- if ( $this->jrn_type !='VEN')
+ if ( $ledger_history->get_ledger_type() !='VEN')
{
$this->write_cell(15,5,sprintf("%.2f",$other['priv']),0,0,'R');
}
$this->write_cell(15,5,sprintf("%.2f",$other['price']),0,0,'R');
- $ret_reconcile=$this->cn->execute('reconcile_date',array($row['id']));
+ $ret_reconcile=$this->cn->execute('reconcile_date',array($row['jr_id']));
$max=Database::num_row($ret_reconcile);
$str_payment="";
if ($max > 0) {
diff --git a/include/class/tax_summary.class.php b/include/class/tax_summary.class.php
index 7de4c8d46..e8ed8824f 100644
--- a/include/class/tax_summary.class.php
+++ b/include/class/tax_summary.class.php
@@ -1,4 +1,5 @@
db=$db;
$this->set_date_start($p_start);
$this->set_date_end($p_end);
+ // By default the TVA is computed by parameter in tva_rate.tva_payment_purchase or tva_rate.tva_payment_sale
+ $this->set_tva_type("T");
+ }
+
+ public function get_tva_type()
+ {
+ return $this->tva_type;
+ }
+
+ public function set_tva_type($tva_type)
+ {
+ $this->tva_type=$tva_type;
+ return $this;
}
/**
@@ -53,7 +69,7 @@ class Tax_Summary
*/
public function set_db($db)
{
- $this->db = $db;
+ $this->db=$db;
return $this;
}
@@ -71,8 +87,9 @@ class Tax_Summary
*/
public function set_date_start($date_start)
{
- if (isDate($date_start) == NULL) throw Exception(_("Format date invalide") . $date_start);
- $this->date_start = $date_start;
+ if (isDate($date_start)==NULL)
+ throw Exception(_("Format date invalide").$date_start);
+ $this->date_start=$date_start;
return $this;
}
@@ -90,8 +107,9 @@ class Tax_Summary
*/
public function set_date_end($date_end)
{
- if (isDate($date_end) == NULL) throw Exception(_("Format date invalide") . $date_end);
- $this->date_end = $date_end;
+ if (isDate($date_end)==NULL)
+ throw Exception(_("Format date invalide").$date_end);
+ $this->date_end=$date_end;
return $this;
}
@@ -101,7 +119,7 @@ class Tax_Summary
*/
function check()
{
- /*-------------SALE ---------------------------------*/
+ /* -------------SALE --------------------------------- */
$sql="select count(*)
from
quant_sold
@@ -113,11 +131,12 @@ class Tax_Summary
and j_date <= to_date($2,'DD.MM.YYYY')
)
";
- $cnt=$this->db->get_value($sql,[$this->date_start,$this->date_end]);
- if ($cnt == 0) {
+ $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]);
+ if ($cnt==0)
+ {
throw new Exception(_("Données manquantes"),100);
}
- /*-------------Purchase ---------------------------------*/
+ /* -------------Purchase --------------------------------- */
$sql="select count(*)
from
quant_purchase
@@ -129,65 +148,33 @@ class Tax_Summary
and j_date <= to_date($2,'DD.MM.YYYY')
)
";
- $cnt=$this->db->get_value($sql,[$this->date_start,$this->date_end]);
- if ($cnt > 0) {
+ $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]);
+ if ($cnt>0)
+ {
throw new Exception(_("Données manquantes"),100);
}
}
-
- /**
- * Total for each sales ledger
- * @return array
- */
- function get_row_sale()
+ private function build_exigibility()
{
global $g_user;
- $sql_ledger=$g_user->get_ledger_sql('ALL',3);
- $sql="with detail_tva as (
- select
- sum(qs_vat) as amount_vat,
- sum(qs_vat_sided) as amount_sided,
- sum(qs_price) as amount_wovat,
- qs_vat_code,
- j_jrn_def
- from
- quant_sold
- join tva_rate on (qs_vat_code=tva_rate.tva_id)
- join jrnx on (quant_sold.j_id=jrnx.j_id)
- join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
- where
- j_date >= to_date($1,'DD.MM.YYYY')
- and j_date <= to_date($2,'DD.MM.YYYY')
- and {$sql_ledger}
- group by j_jrn_def,qs_vat_code)
- select jrn_def_name,
- tva_label ,
- qs_vat_code,
- tva_rate,
- tva_both_side,
- amount_vat,
- amount_wovat,
- amount_sided
- from
- detail_tva
- join tva_rate on (tva_rate.tva_id=qs_vat_code)
- join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
-
- order by jrn_def_name,tva_label";
- $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]);
- return $array;
-
+ $sql_ledger=$g_user->get_ledger_sql('ALL', 3);
+
}
-
-
/**
- * Total for each purchase ledger
- * @return array
+ * Build the SQL for sale vat
+ * @return string
+ *
*/
- function get_row_purchase()
+ private function build_sql_purchase($p_group_ledger)
{
global $g_user;
- $sql_ledger=$g_user->get_ledger_sql('ALL',3);
+ $sql_ledger=$g_user->get_ledger_sql('ACH', 3);
+ $group_ledger="";
+ if ( $p_group_ledger )
+ {
+ $group_ledger='j_jrn_def,';
+ }
+
$sql="with detail_tva as (
select
sum(qp_vat) as amount_vat,
@@ -197,18 +184,163 @@ class Tax_Summary
sum(qp_nd_tva) as amount_noded_tax,
sum(qp_nd_tva_recup) as amount_noded_return,
sum(qp_dep_priv) as amount_private,
- qp_vat_code,
- j_jrn_def
+ {$group_ledger}
+ qp_vat_code
from
quant_purchase
join tva_rate on (qp_vat_code=tva_rate.tva_id)
join jrnx on (quant_purchase.j_id=jrnx.j_id)
join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
+ join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)
+ ";
+ if ( $this->tva_type=="O")
+ {
+ $sql=$sql."
where
j_date >= to_date($1,'DD.MM.YYYY')
and j_date <= to_date($2,'DD.MM.YYYY')
and {$sql_ledger}
- group by j_jrn_def,qp_vat_code)
+ group by {$group_ledger} qp_vat_code) ";
+ } elseif ($this->tva_type=="P") {
+ $sql=$sql."
+ where
+ coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
+ to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
+ and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
+ to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
+ and {$sql_ledger}
+ group by {$group_ledger} qp_vat_code) ";
+ }elseif ($this->tva_type=="T") {
+ $sql=$sql." where
+ ( tva_rate.tva_payment_purchase='P'
+ and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
+ to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
+ and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
+ to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
+ )
+ or
+ ( tva_rate.tva_payment_purchase='O'
+ and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
+ to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
+ and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
+ to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
+ )
+ and {$sql_ledger}
+ group by {$group_ledger} qp_vat_code) ";
+
+ } else {
+ throw new Exception(_("Exig TVA invalide"),1001);
+ }
+ return $sql;
+ }
+ /**
+ * Build the SQL for sale vat
+ *
+ * @param group by ledger
+ *
+ * @return string
+ *
+ */
+ private function build_sql_sale($p_group_ledger=TRUE)
+ {
+ global $g_user;
+ $sql_ledger=$g_user->get_ledger_sql('VEN', 3);
+ $group_ledger="";
+ if ( $p_group_ledger )
+ {
+ $group_ledger='j_jrn_def,';
+ }
+ $sql="with detail_tva as (
+ select
+ sum(qs_vat) as amount_vat,
+ sum(qs_vat_sided) as amount_sided,
+ sum(qs_price) as amount_wovat,
+ {$group_ledger}
+ qs_vat_code
+ from
+ quant_sold
+ join tva_rate on (qs_vat_code=tva_rate.tva_id)
+ join jrnx on (quant_sold.j_id=jrnx.j_id)
+ join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
+ join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)";
+ if ( $this->tva_type=="O")
+ {
+ $sql=$sql."
+ where
+ j_date >= to_date($1,'DD.MM.YYYY')
+ and j_date <= to_date($2,'DD.MM.YYYY')
+ and {$sql_ledger}
+ group by {$group_ledger} qs_vat_code) ";
+
+ } elseif ($this->tva_type=="P") {
+ $sql=$sql."
+ where
+ coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
+ to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
+ and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
+ to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
+ and {$sql_ledger}
+ group by {$group_ledger} qs_vat_code) ";
+
+ } elseif ($this->tva_type=="T") {
+ $sql=$sql."
+ where
+ ( tva_rate.tva_payment_sale='P'
+ and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
+ to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
+ and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
+ to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
+ )
+ or
+ ( tva_rate.tva_payment_sale='O'
+ and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
+ to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
+ and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
+ to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
+ )
+ and {$sql_ledger}
+ group by {$group_ledger} qs_vat_code)
+ ";
+ }
+ else {
+ throw new Exception(_("Exig TVA invalide"),1001);
+ }
+ return $sql;
+ }
+ /**
+ * Total for each sales ledger
+ * @return array
+ */
+ function get_row_sale()
+ {
+ $sql=$this->build_sql_sale(TRUE);
+ $sql.="
+ select jrn_def_name,
+ tva_label ,
+ qs_vat_code,
+ tva_rate,
+ tva_both_side,
+ amount_vat,
+ amount_wovat,
+ amount_sided,
+ tva_payment_sale as tva_type
+ from
+ detail_tva
+ join tva_rate on (tva_rate.tva_id=qs_vat_code)
+ join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
+ order by jrn_def_name,tva_label";
+
+ $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
+ return $array;
+ }
+
+ /**
+ * Total for each purchase ledger
+ * @return array
+ */
+ function get_row_purchase()
+ {
+ $sql=$this->build_sql_purchase(TRUE)."
select jrn_def_name,
tva_label ,
tva_rate,
@@ -226,7 +358,7 @@ class Tax_Summary
join tva_rate on (tva_rate.tva_id=qp_vat_code)
join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
order by jrn_def_name,tva_label";
- $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]);
+ $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
return $array;
}
@@ -235,66 +367,31 @@ class Tax_Summary
*/
function get_summary_sale()
{
- global $g_user;
- $sql_ledger=$g_user->get_ledger_sql('ALL',3);
- $sql="with detail_tva as (
- select
- sum(qs_vat) as amount_vat,
- sum(qs_vat_sided) as amount_sided,
- sum(qs_price) as amount_wovat,
- qs_vat_code
- from
- quant_sold
- join tva_rate on (qs_vat_code=tva_rate.tva_id)
- join jrnx on (quant_sold.j_id=jrnx.j_id)
- join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
- where
- j_date >= to_date($1,'DD.MM.YYYY')
- and j_date <= to_date($2,'DD.MM.YYYY')
- and {$sql_ledger}
- group by qs_vat_code)
- select
- tva_label ,
- qs_vat_code,
- tva_rate,
+ $sql=$this->build_sql_sale(FALSE);
+ $sql.="select
+ tva_label ,
+ qs_vat_code,
+ tva_rate,
tva_both_side,
- amount_vat,
- amount_wovat,
- amount_sided
- from
- detail_tva
- join tva_rate on (tva_rate.tva_id=qs_vat_code)
+ amount_vat,
+ amount_wovat,
+ amount_sided,
+ tva_rate.tva_payment_sale
+ from
+ detail_tva
+ join tva_rate on (tva_rate.tva_id=qs_vat_code)
order by tva_label";
- $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]);
+ $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
return $array;
}
+
/**
* Summary for all purchase ledger
*/
function get_summary_purchase()
{
- global $g_user;
- $sql_ledger=$g_user->get_ledger_sql('ALL',3);
- $sql="with detail_tva as (
- select
- sum(qp_vat) as amount_vat,
- sum(qp_vat_sided) as amount_sided,
- sum(qp_price) as amount_wovat,
- sum(qp_nd_amount) as amount_noded_amount,
- sum(qp_nd_tva) as amount_noded_tax,
- sum(qp_nd_tva_recup) as amount_noded_return,
- sum(qp_dep_priv) as amount_private,
- qp_vat_code
- from
- quant_purchase
- join tva_rate on (qp_vat_code=tva_rate.tva_id)
- join jrnx on (quant_purchase.j_id=jrnx.j_id)
- join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
- where
- j_date >= to_date($1,'DD.MM.YYYY')
- and j_date <= to_date($2,'DD.MM.YYYY')
- and {$sql_ledger}
- group by qp_vat_code)
+
+ $sql=$this->build_sql_purchase(FALSE)."
select
tva_label ,
tva_rate,
@@ -311,10 +408,11 @@ class Tax_Summary
detail_tva
join tva_rate on (tva_rate.tva_id=qp_vat_code)
order by tva_label";
- $array=$this->db->get_array($sql,[$this->date_start,$this->date_end]);
+ $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
return $array;
}
+
/**
* @brief display the summary of VAT in the range of date
*/
@@ -322,6 +420,7 @@ class Tax_Summary
{
require_once NOALYSS_INCLUDE."/template/tax_summary_display.php";
}
+
/**
* @brief display a form to export in CSV
* @see export_printtva_csv.php
@@ -330,11 +429,12 @@ class Tax_Summary
{
echo '';
}
@@ -346,13 +446,12 @@ class Tax_Summary
{
echo '';
}
-
}
diff --git a/include/class/tva_rate_mtable.class.php b/include/class/tva_rate_mtable.class.php
index 6e21d10e4..4ffba15ac 100644
--- a/include/class/tva_rate_mtable.class.php
+++ b/include/class/tva_rate_mtable.class.php
@@ -57,7 +57,22 @@ class Tva_Rate_MTable extends Manage_Table_SQL
["value"=>1, "label"=>_("Autoliquidation")]
));
$this->set_property_updatable("tva_id", FALSE);
- $this->a_info=["tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45];
+ $this->set_col_label("tva_payment_purchase",_("Exigible achat"));
+ $this->set_col_type("tva_payment_purchase","select",
+ array(
+ array("value"=>'O',"label"=>"Opération"),
+ array("value"=>'P',"label"=>"Paiement")
+ )
+ );
+ $this->set_col_label("tva_payment_sale",_("Exigible vente"));
+ $this->set_col_type("tva_payment_sale","select",
+ array(
+ array("value"=>'O',"label"=>"Opération"),
+ array("value"=>'P',"label"=>"Paiement")
+ )
+ );
+ $this->a_info=["tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45
+ ,"tva_payment_sale"=>74,"tva_payment_purchase"=>74];
}
/**
@@ -183,6 +198,8 @@ class Tva_Rate_MTable extends Manage_Table_SQL
$tva_purchase=(trim($this->table->tva_purchase)=="")?"#":$this->table->tva_purchase;
$tva_sale=(trim($this->table->tva_sale)=="")?"#":$this->table->tva_sale;
$tva_rate->setp("tva_poste", $tva_purchase.",".$tva_sale);
+ $tva_rate->setp("tva_payment_sale", $this->table->tva_payment_sale);
+ $tva_rate->setp("tva_payment_purchase", $this->table->tva_payment_purchase);
$tva_rate->save();
// reload the row
diff --git a/include/constant.php b/include/constant.php
index ff6ec01ca..d73519b0a 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -108,7 +108,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) {
if ( ! defined ("SYSINFO_DISPLAY")) {
define ("SYSINFO_DISPLAY",TRUE);
}
-define ("DBVERSION",138);
+define ("DBVERSION",141);
define ("MONO_DATABASE",25);
define ("DBVERSIONREPO",18);
define ('NOTFOUND','--not found--');
diff --git a/include/database/tva_rate_sql.class.php b/include/database/tva_rate_sql.class.php
index da6c95c55..f23d98b52 100644
--- a/include/database/tva_rate_sql.class.php
+++ b/include/database/tva_rate_sql.class.php
@@ -45,6 +45,8 @@ class Tva_rate_SQL extends Noalyss_SQL
, "tva_comment"=>"tva_comment"
, "tva_poste"=>"tva_poste"
, "tva_both_side"=>"tva_both_side"
+ ,"tva_payment_purchase"=>"tva_payment_purchase"
+ ,"tva_payment_sale"=>"tva_payment_sale"
);
/*
* Type of columns
@@ -56,6 +58,9 @@ class Tva_rate_SQL extends Noalyss_SQL
, "tva_comment"=>"text"
, "tva_poste"=>"text"
, "tva_both_side"=>"numeric"
+ ,"tva_payment_purchase"=>"text"
+ ,"tva_payment_sale"=>"text"
+
);
diff --git a/include/database/user_filter_sql.class.php b/include/database/user_filter_sql.class.php
index 4f5e56959..72ebb83c9 100644
--- a/include/database/user_filter_sql.class.php
+++ b/include/database/user_filter_sql.class.php
@@ -54,7 +54,7 @@ class User_filter_SQL extends Noalyss_SQL
, "date_paid_end"=>"date_paid_end"
, "ledger_type"=>"ledger_type"
, "all_ledger"=>"all_ledger"
- ,"unpaid"=>"unpaid"
+ ,"operation_filter"=>"operation_filter"
,'filter_name'=>"filter_name"
);
/*
@@ -76,7 +76,7 @@ class User_filter_SQL extends Noalyss_SQL
, "date_paid_end"=>"text"
, "ledger_type"=>"text"
, "all_ledger"=>"numeric"
- ,"unpaid"=>"text"
+ ,"operation_filter"=>"text"
,"filter_name"=>"text"
);
diff --git a/include/database/v_tva_rate_sql.class.php b/include/database/v_tva_rate_sql.class.php
index 701bdc3ea..19c63fe3c 100644
--- a/include/database/v_tva_rate_sql.class.php
+++ b/include/database/v_tva_rate_sql.class.php
@@ -46,6 +46,9 @@ class V_Tva_Rate_SQL extends Noalyss_SQL
, "tva_purchase"=>"tva_purchase"
, "tva_sale"=>"tva_sale"
, "tva_both_side"=>"tva_both_side"
+ ,'tva_payment_purchase'=>'tva_payment_purchase'
+ ,'tva_payment_sale'=>'tva_payment_sale'
+
);
/*
* Type of columns
@@ -58,6 +61,8 @@ class V_Tva_Rate_SQL extends Noalyss_SQL
, "tva_purchase"=>"text"
, "tva_sale"=>"text"
, "tva_both_side"=>"numeric"
+ , 'tva_payment_purchase'=>'text'
+ , 'tva_payment_sale'=>'text'
);
diff --git a/include/export/export_ledger_csv.php b/include/export/export_ledger_csv.php
index b3159e1b4..c9dfbf88b 100644
--- a/include/export/export_ledger_csv.php
+++ b/include/export/export_ledger_csv.php
@@ -28,19 +28,22 @@
*/
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
+
include_once NOALYSS_INCLUDE."/lib/ac_common.php";
require_once NOALYSS_INCLUDE.'/class/noalyss_parameter_folder.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php';
require_once NOALYSS_INCLUDE.'/class/print_ledger.class.php';
-require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
-$gDossier=dossier::id();
+
+require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
require_once NOALYSS_INCLUDE.'/class/database.class.php';
require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
-
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
+
+
+$gDossier=dossier::id();
$http=new HttpInput();
$export=new Noalyss_Csv(_('journal'));
@@ -57,6 +60,7 @@ try
$get_option=$http->get('p_simple', "string");
$get_from_periode=$http->get('from_periode', 'number');
$get_to_periode=$http->get('to_periode', 'number');
+ $filter_operation=$http->get("operation_type");
}
catch (Exception $exc)
{
@@ -86,12 +90,13 @@ if ($get_jrn==0)
{
// find out all the available ledgers for the current user
$a_jrn=Print_Ledger::available_ledger($get_from_periode);
+ $Jrn=new Acc_Ledger($cn,0);
}
else
{
$a_jrn=$get_jrn;
+ $Jrn=new Acc_Ledger($cn, $get_jrn);
}
-$Jrn=new Acc_Ledger($cn, $get_jrn);
$Jrn->get_name();
$jrn_type=$Jrn->get_type();
@@ -119,14 +124,14 @@ if ( $get_option=="E")
case 'VEN':
$ledger=new Acc_Ledger_Sold($cn, $get_jrn);
$ret_detail=$ledger->get_detail_sale($get_from_periode,
- $get_to_periode);
+ $get_to_periode,$filter_operation);
$a_heading=Acc_Ledger_Sold::heading_detail_sale();
break;
case 'ACH':
$ledger=new Acc_Ledger_Purchase($cn, $get_jrn);
$ret_detail=$ledger->get_detail_purchase($get_from_periode,
- $get_to_periode);
+ $get_to_periode,$filter_operation);
$a_heading=Acc_Ledger_Purchase::heading_detail_purchase();
break;
default:
@@ -199,6 +204,7 @@ if ($get_option=='A')
$get_from_periode, $get_to_periode, 'A');
}
+ $acc_ledger_history->set_filter_operation($filter_operation);
$acc_ledger_history->export_csv();
exit;
}
@@ -308,6 +314,7 @@ if ($get_option=="L" || $get_option == 'D')
$get_from_periode, $get_to_periode, 'D');
}
+ $acc_ledger_history->set_filter_operation($filter_operation);
$acc_ledger_history->export_csv();
return;
}
@@ -319,12 +326,14 @@ if ($get_option=="L" || $get_option == 'D')
{
$acc_ledger_history=new Acc_Ledger_History_Purchase($cn, [$Jrn->id],
$get_from_periode, $get_to_periode, 'D');
+ $acc_ledger_history->set_filter_operation($filter_operation);
$acc_ledger_history->export_csv();
}
if ($jrn_type=="VEN")
{
$acc_ledger_history=new Acc_Ledger_History_Sale($cn, [$Jrn->id],
$get_from_periode, $get_to_periode, 'D');
+ $acc_ledger_history->set_filter_operation($filter_operation);
$acc_ledger_history->export_csv();
}
}
diff --git a/include/export/export_ledger_pdf.php b/include/export/export_ledger_pdf.php
index 5312ca267..9ed69aa81 100644
--- a/include/export/export_ledger_pdf.php
+++ b/include/export/export_ledger_pdf.php
@@ -46,7 +46,9 @@ try
{
$jrn_id=$http->get('jrn_id',"number");
$p_simple=$http->get('p_simple',"string");
-
+ $filter_operation=$http->get("operation_type");
+ $from=$http->get("from_periode","number");
+ $to=$http->get("to_periode","number");
}
catch (Exception $exc)
@@ -71,11 +73,10 @@ if ($jrn_id != 0 && $g_user->check_jrn($jrn_id) == 'X') {
}
$ret = "";
-
+if ( $jrn_id == 0 ) $Jrn->id=0;
$jrn_type = $Jrn->get_type();
-$pdf = Print_Ledger::factory($cn, $p_simple, "PDF", $Jrn);
-
+$pdf = Print_Ledger::factory($cn, $p_simple, $Jrn,$from,$to,$filter_operation);
$pdf->setDossierInfo($Jrn->jrn_def_name);
$pdf->AliasNbPages();
$pdf->AddPage();
diff --git a/include/export/export_printtva_csv.php b/include/export/export_printtva_csv.php
index ebe8ddde4..b5c75196d 100644
--- a/include/export/export_printtva_csv.php
+++ b/include/export/export_printtva_csv.php
@@ -30,6 +30,9 @@ require_once NOALYSS_INCLUDE."/class/tax_summary.class.php";
require_once NOALYSS_INCLUDE."/lib/noalyss_csv.class.php";
$http=new HttpInput();
$tax_summary = new Tax_Summary($cn,$http->get("date_start"),$http->get("date_end"));
+$tva_type = $http->request("tva_type");
+$tax_summary->set_tva_type($tva_type);
+
try {
$tax_summary->check();
}catch (Exception $e)
diff --git a/include/export/export_printtva_pdf.php b/include/export/export_printtva_pdf.php
index 028db71e2..4954bf4ac 100644
--- a/include/export/export_printtva_pdf.php
+++ b/include/export/export_printtva_pdf.php
@@ -34,6 +34,7 @@ $http = new HttpInput();
$from_periode = $http->request("date_start");
$to_periode = $http->request("date_end");
+$tva_type = $http->request("tva_type");
$gDossier = dossier::id();
@@ -41,6 +42,7 @@ $gDossier = dossier::id();
/* Security */
$cn = Dossier::connect();
$tax_summary = new Tax_Summary($cn, $from_periode, $to_periode);
+$tax_summary->set_tva_type($tva_type);
$pdf = new PDFLand($cn);
$pdf->setDossierInfo(sprintf(_("Date") . " : %s %s", $from_periode, $to_periode));
$pdf->AliasNbPages();
@@ -172,7 +174,7 @@ for ($i = 0; $i < $nb_sale; $i++) {
}
$pdf->line_new();
-$nb_array = count($array);
+$nb_array = count($a_sum);
// initialize totals
for ($e=2;$e<$nb_col;$e++){
$a_tot[$a_col[$e]]=0;
@@ -185,14 +187,14 @@ for ($i = 0; $i < $nb_array; $i++) {
$colname=$a_col[$e];
if ( $e ==0 ) {
// first column TVA_LABEL
- $pdf->write_cell(40, 5, $array[$i][$colname], 1, 0, 'L');
+ $pdf->write_cell(40, 5, $a_sum[$i][$colname], 1, 0, 'L');
} elseif ($e == 1 ){
// Secund col. tva rate
- $pdf->write_cell(40, 5, nbm($array[$i][$colname]*100), 1, 0, 'R');
+ $pdf->write_cell(40, 5, nbm($a_sum[$i][$colname]*100), 1, 0, 'R');
}else {
// Other cols,display amount and compute total
- $a_tot[$colname] = bcadd($a_tot[$colname], $array[$i][$colname]);
- $pdf->write_cell(40, 5, nbm($array[$i][$colname]), 1, 0, 'R');
+ $a_tot[$colname] = bcadd($a_tot[$colname], $a_sum[$i][$colname]);
+ $pdf->write_cell(40, 5, nbm($a_sum[$i][$colname]), 1, 0, 'R');
}
}
$pdf->line_new();
@@ -326,6 +328,7 @@ for ($e=0;$e<$nb_col;$e++){
}
$pdf->line_new();
+$array=$tax_summary->get_summary_purchase();
$nb_array = count($array);
// initialize totals
for ($e=2;$e<$nb_col;$e++){
diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php
index 0b81f45a6..aaaadd12b 100644
--- a/include/impress_jrn.inc.php
+++ b/include/impress_jrn.inc.php
@@ -150,6 +150,20 @@ $a = array(
);
$w->selected = 1;
print '
';
+/// All operation
+$s_operation = new ISelect("operation_type");
+$s_operation->value=array(
+ array("label"=>_("Toutes les opérations"),"value"=>"all"),
+ array("label"=>_("Uniquement payées"),"value"=>"paid"),
+ array("label"=>_("Uniquement non payées"),"value"=>"unpaid")
+ );
+$s_operation->selected=$http->get("operation_type","string","all");
+echo "
";
+echo td(_("Uniquement pour journaux vente et achat").Icon_Action::infobulle(75));
+echo td($s_operation->input());
+echo '
';
+
+/// Type of printing
print '
';
$simple=$http->get("p_simple","string","L");
$w->selected = $simple;
@@ -182,6 +196,7 @@ if (isset($_REQUEST['bt_html']))
$hid->input("jrn_id", $jrn_id) .
$hid->input("from_periode", $from_periode) .
$hid->input("to_periode", $to_periode);
+ echo $hid->input("operation_type", $s_operation->selected);
echo $hid->input("p_simple", $simple);
echo HtmlInput::get_to_hidden(array('ac', 'type'));
echo "";
@@ -195,6 +210,7 @@ if (isset($_REQUEST['bt_html']))
$hid->input("from_periode", $from_periode) .
$hid->input("to_periode", $to_periode);
echo $hid->input("p_simple", $simple);
+ echo $hid->input("operation_type", $s_operation->selected);
echo HtmlInput::get_to_hidden(array('ac', 'type'));
echo "";
@@ -220,7 +236,7 @@ if (isset($_REQUEST['bt_html']))
$a_ledger=[$jrn_id];
}
- $ledger_history=Acc_Ledger_History::factory($cn,$a_ledger,$from_periode,$to_periode,$simple);
+ $ledger_history=Acc_Ledger_History::factory($cn,$a_ledger,$from_periode,$to_periode,$simple,$s_operation->selected);
$ledger_history->export_html();
diff --git a/include/lib/database_core.class.php b/include/lib/database_core.class.php
index 8a8d3d24c..3deb582af 100644
--- a/include/lib/database_core.class.php
+++ b/include/lib/database_core.class.php
@@ -953,7 +953,7 @@ class DatabaseCore
static function nb_column($p_ret) {
return pg_num_fields($p_ret);
}
-
+
}
/* test::test_me(); */
diff --git a/include/lib/message_javascript.php b/include/lib/message_javascript.php
index 9333a2dd2..c702b588e 100644
--- a/include/lib/message_javascript.php
+++ b/include/lib/message_javascript.php
@@ -104,4 +104,6 @@ content[70]="";
content[72]="";
content[73]="";
+content[74]="";
+content[75]="";
\ No newline at end of file
diff --git a/include/lib/noalyss_sql.class.php b/include/lib/noalyss_sql.class.php
index 1eb466d3b..25edb2f57 100644
--- a/include/lib/noalyss_sql.class.php
+++ b/include/lib/noalyss_sql.class.php
@@ -312,16 +312,17 @@ abstract class Noalyss_SQL extends Data_SQL
return $this;
}
/**
- * Turn an object (row) into an array
+ * Turn an object (row) into an array, and the key could be prefixed with $prefix
+ * @param string $prefix before the key
* @return array
*/
- public function to_array()
+ public function to_array($prefix="")
{
$array=array();
foreach ($this->name as $key=> $value)
{
-
- $array[$key]=$this->$key;
+ $nkey=$prefix.$key;
+ $array[$nkey]=$this->$key;
}
return $array;
}
diff --git a/include/sql/patch/upgrade138.sql b/include/sql/patch/upgrade138.sql
new file mode 100644
index 000000000..39e5b3118
--- /dev/null
+++ b/include/sql/patch/upgrade138.sql
@@ -0,0 +1,36 @@
+begin;
+ALTER TABLE public.tva_rate ADD tva_payment_sale char(1) NULL DEFAULT 'O';
+update public.tva_rate set tva_payment_sale='O';
+ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_sale_check CHECK (tva_payment_sale in ('O','P'));
+comment on column public.tva_rate.tva_payment_sale is 'Check if the VAT on Sale must be declared when at the date of payment (P) or the date of operation (O)';
+
+
+ALTER TABLE public.tva_rate ADD tva_payment_purchase char(1) NULL DEFAULT 'O';
+update public.tva_rate set tva_payment_purchase='O';
+ALTER TABLE public.tva_rate ADD CONSTRAINT tva_rate_purchase_check CHECK (tva_payment_purchase in ('O','P'));
+comment on column public.tva_rate.tva_payment_purchase is 'Check if the VAT on Purchase must be declared when at the date of payment (P) or the date of operation (O)';
+
+
+drop VIEW public.v_tva_rate;
+
+CREATE OR REPLACE VIEW public.v_tva_rate
+AS SELECT tva_rate.tva_id,
+ tva_rate.tva_rate,
+ tva_rate.tva_label,
+ tva_rate.tva_comment,
+ split_part(tva_rate.tva_poste, ','::text, 1) AS tva_purchase,
+ split_part(tva_rate.tva_poste, ','::text, 2) AS tva_sale,
+ tva_rate.tva_both_side,
+ tva_payment_purchase,
+ tva_payment_sale
+ FROM tva_rate;
+
+COMMENT ON VIEW public.v_tva_rate IS 'Show this table to be easily used by Tva_Rate_MTable';
+COMMENT ON COLUMN public.v_tva_rate.tva_purchase IS ' VAT used for purchase';
+COMMENT ON COLUMN public.v_tva_rate.tva_sale IS ' VAT used for sale';
+COMMENT ON COLUMN public.v_tva_rate.tva_both_side IS 'if 1 , VAT avoided ';
+comment on column public.v_tva_rate.tva_payment_purchase is 'Check if the VAT on Purchase must be declared when at the date of payment (P) or the date of operation (O)';
+comment on column public.v_tva_rate.tva_payment_sale is 'Check if the VAT on Sale must be declared when at the date of payment (P) or the date of operation (O)';
+
+insert into version (val,v_description) values (139,'Add VAT exigibility');
+commit ;
\ No newline at end of file
diff --git a/include/sql/patch/upgrade139.sql b/include/sql/patch/upgrade139.sql
new file mode 100644
index 000000000..105adfa4c
--- /dev/null
+++ b/include/sql/patch/upgrade139.sql
@@ -0,0 +1,119 @@
+begin;
+DROP VIEW public.v_detail_sale;
+DROP VIEW public.v_detail_purchase;
+
+CREATE OR REPLACE VIEW public.v_detail_sale
+AS WITH m AS (
+ SELECT sum(quant_sold_1.qs_price) AS htva,
+ sum(quant_sold_1.qs_vat) AS tot_vat,
+ sum(quant_sold_1.qs_vat_sided) AS tot_tva_np,
+ jrn_1.jr_id
+ FROM quant_sold quant_sold_1
+ JOIN jrnx jrnx_1 USING (j_id)
+ JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id
+ GROUP BY jrn_1.jr_id
+ )
+ SELECT jrn.jr_id,
+ jrn.jr_date,
+ jrn.jr_date_paid,
+ jrn.jr_ech,
+ jrn.jr_tech_per,
+ jrn.jr_comment,
+ jrn.jr_pj_number,
+ jrn.jr_internal,
+ jrn.jr_def_id,
+ jrnx.j_poste,
+ jrnx.j_text,
+ jrnx.j_qcode,
+ jrn.jr_rapt,
+ quant_sold.qs_fiche AS item_card,
+ a.name AS item_name,
+ quant_sold.qs_client,
+ b.vw_name AS tiers_name,
+ b.quick_code,
+ tva_rate.tva_label,
+ tva_rate.tva_comment,
+ tva_rate.tva_both_side,
+ quant_sold.qs_vat_sided AS vat_sided,
+ quant_sold.qs_vat_code AS vat_code,
+ quant_sold.qs_vat AS vat,
+ quant_sold.qs_price AS price,
+ quant_sold.qs_quantite AS quantity,
+ quant_sold.qs_price / quant_sold.qs_quantite AS price_per_unit,
+ m.htva,
+ m.tot_vat,
+ m.tot_tva_np,
+ oc.oc_amount,
+ oc.oc_vat_amount,
+ ( SELECT currency.cr_code_iso
+ FROM currency
+ WHERE jrn.currency_id = currency.id) AS cr_code_iso
+ FROM jrn
+ JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
+ JOIN quant_sold USING (j_id)
+ JOIN vw_fiche_name a ON quant_sold.qs_fiche = a.f_id
+ JOIN vw_fiche_attr b ON quant_sold.qs_client = b.f_id
+ JOIN tva_rate ON quant_sold.qs_vat_code = tva_rate.tva_id
+ JOIN m ON m.jr_id = jrn.jr_id
+ LEFT JOIN operation_currency oc ON oc.j_id = jrnx.j_id;
+
+
+CREATE OR REPLACE VIEW public.v_detail_purchase
+AS WITH m AS (
+ SELECT sum(quant_purchase_1.qp_price) AS htva,
+ sum(quant_purchase_1.qp_vat) AS tot_vat,
+ sum(quant_purchase_1.qp_vat_sided) AS tot_tva_np,
+ jrn_1.jr_id
+ FROM quant_purchase quant_purchase_1
+ JOIN jrnx jrnx_1 USING (j_id)
+ JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id
+ GROUP BY jrn_1.jr_id
+ )
+ SELECT jrn.jr_id,
+ jrn.jr_date,
+ jrn.jr_date_paid,
+ jrn.jr_ech,
+ jrn.jr_tech_per,
+ jrn.jr_comment,
+ jrn.jr_pj_number,
+ jrn.jr_internal,
+ jrn.jr_def_id,
+ jrnx.j_poste,
+ jrnx.j_text,
+ jrnx.j_qcode,
+ jrn.jr_rapt,
+ quant_purchase.qp_fiche AS item_card,
+ a.name AS item_name,
+ quant_purchase.qp_supplier,
+ b.vw_name AS tiers_name,
+ b.quick_code,
+ tva_rate.tva_label,
+ tva_rate.tva_comment,
+ tva_rate.tva_both_side,
+ quant_purchase.qp_vat_sided AS vat_sided,
+ quant_purchase.qp_vat_code AS vat_code,
+ quant_purchase.qp_vat AS vat,
+ quant_purchase.qp_price AS price,
+ quant_purchase.qp_quantite AS quantity,
+ quant_purchase.qp_price / quant_purchase.qp_quantite AS price_per_unit,
+ quant_purchase.qp_nd_amount AS non_ded_amount,
+ quant_purchase.qp_nd_tva AS non_ded_tva,
+ quant_purchase.qp_nd_tva_recup AS non_ded_tva_recup,
+ m.htva,
+ m.tot_vat,
+ m.tot_tva_np,
+ oc.oc_amount,
+ oc.oc_vat_amount,
+ ( SELECT currency.cr_code_iso
+ FROM currency
+ WHERE jrn.currency_id = currency.id) AS cr_code_iso
+ FROM jrn
+ JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
+ JOIN quant_purchase USING (j_id)
+ JOIN vw_fiche_name a ON quant_purchase.qp_fiche = a.f_id
+ JOIN vw_fiche_attr b ON quant_purchase.qp_supplier = b.f_id
+ JOIN tva_rate ON quant_purchase.qp_vat_code = tva_rate.tva_id
+ JOIN m ON m.jr_id = jrn.jr_id
+ LEFT JOIN operation_currency oc ON oc.j_id = jrnx.j_id;
+insert into version (val,v_description) values (140,'Filter operation PRINTJRN');
+commit ;
\ No newline at end of file
diff --git a/include/tax_summary.inc.php b/include/tax_summary.inc.php
index 0623edde9..42fd3a2c4 100644
--- a/include/tax_summary.inc.php
+++ b/include/tax_summary.inc.php
@@ -36,6 +36,15 @@ $end_periode = new IDate("end_date", $end);
echo '