Plugins  LAST
 All Data Structures Files Functions Variables Pages
Public Member Functions | Static Public Member Functions
Rapav_dd_Account Class Reference

handle the param_detail type Account The type_sum_account gives the type of total More...

Inheritance diagram for Rapav_dd_Account:
Inheritance graph
Collaboration diagram for Rapav_dd_Account:
Collaboration graph

Public Member Functions

 compute ($p_start, $p_end)
 
 from_array ($p_array)
 the p_array contains a row from formulaire_param_detail it will be copied into this->form. More...
 

Static Public Member Functions

static factory ($p_array)
 create an object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or Rapav_dd_compute following the idx type_detail More...
 

Detailed Description

handle the param_detail type Account The type_sum_account gives the type of total

Definition at line 1142 of file class_rapav_declaration.php.

Member Function Documentation

Rapav_dd_Account::compute (   $p_start,
  $p_end 
)

Definition at line 1145 of file class_rapav_declaration.php.

References $amount, $cn, $sql, and RAPAV\get_sql_date().

1146  {
1147  global $cn;
1148  $filter_ledger = "";
1149  if ($this->form->jrn_def_id != "")
1150  {
1151  $filter_ledger = " and jrn1.j_jrn_def = " . sql_string($this->form->jrn_def_id);
1152  }
1153 
1154  $amount=0;
1155 
1156  bcscale(2);
1157  switch ($this->form->type_sum_account)
1158  {
1159  // Saldo
1160  case 1:
1161  case 2:
1162  $sql_date=RAPAV::get_sql_date($this->form->date_paid,'jrn1' );
1163  // Compute D-C
1164  $sql = "
1165  select sum(jrnx_amount)
1166  from (
1167  select distinct jrn1.j_id,case when jrn1.j_debit = 't' then jrn1.j_montant else jrn1.j_montant*(-1) end as jrnx_amount
1168  from jrnx as jrn1
1169  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1170  where
1171  jrn1.j_poste like $1
1172  $sql_date
1173  and
1174  jrn2.j_poste like $4
1175  $filter_ledger
1176  ) as tv_amount
1177  ";
1178  $amount = $cn->get_value($sql, array(
1179  $this->form->tmp_val,
1180  $p_start,
1181  $p_end,
1182  $this->form->with_tmp_val
1183  ));
1184  // if C-D is asked then reverse the result
1185  if ($this->form->type_sum_account == 2)
1186  $amount = bcmul($amount, -1);
1187  break;
1188  // Only DEBIT
1189  case 3:
1190  $sql_date=RAPAV::get_sql_date($this->form->date_paid,'jrn1' );
1191  $sql = "
1192  select sum(jrnx_amount)
1193  from (
1194  select distinct jrn1.j_id,jrn1.j_montant as jrnx_amount
1195  from jrnx as jrn1
1196  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1197  where
1198  jrn1.j_poste like $1
1199  $sql_date
1200  and
1201  jrn2.j_poste like $4
1202  and
1203  jrn1.j_debit='t'
1204  $filter_ledger
1205  ) as tv_amount
1206  ";
1207  $amount = $cn->get_value($sql, array(
1208  $this->form->tmp_val,
1209  $p_start,
1210  $p_end,
1211  $this->form->with_tmp_val
1212  ));
1213  break;
1214  // Only CREDIT
1215  case 4:
1216  $sql_date=RAPAV::get_sql_date($this->form->date_paid,'jrn1' );
1217  $sql = "
1218  select sum(jrnx_amount)
1219  from (
1220  select distinct jrn1.j_id,jrn1.j_montant as jrnx_amount
1221  from jrnx as jrn1
1222  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1223  where
1224  jrn1.j_poste like $1
1225  $sql_date
1226  and
1227  jrn2.j_poste like $4
1228  and
1229  jrn1.j_debit='f'
1230  $filter_ledger
1231  ) as tv_amount
1232  ";
1233  $amount = $cn->get_value($sql, array(
1234  $this->form->tmp_val,
1235  $p_start,
1236  $p_end,
1237  $this->form->with_tmp_val,
1238  ));
1239  break;
1240 
1241  default:
1242  if (DEBUG)
1243  var_dump($this);
1244  die(__FILE__ . ":" . __LINE__ . " UNKNOW SUM TYPE");
1245  break;
1246  }
1247  /*
1248  * 4 possibilities with type_sum_account
1249  */
1250  return $amount;
1251  }
static get_sql_date($p_date, $p_prefix="")
Compute the SQL for the date.
Definition: class_rapav.php:84
$sql
global $cn
static Rapav_Declaration_Detail::factory (   $p_array)
staticinherited

create an object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or Rapav_dd_compute following the idx type_detail

Parameters
type$p_array
Returns
object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or Rapav_dd_compute
Exceptions
ifthe type is not known

Definition at line 843 of file class_rapav_declaration.php.

References $ret.

Referenced by Rapav_Declaration_Param\compute(), and Rapav_Declaration_Param\compute_child().

844  {
845  switch ($p_array['type_detail'])
846  {
847  case '1':
848  $ret = new Rapav_dd_Formula();
849  break;
850  case '2':
851  $ret = new Rapav_dd_Account_Tva();
852  break;
853  case '3':
854  $ret = new Rapav_dd_Compute();
855  break;
856  case '4':
857  $ret = new Rapav_dd_Account();
858  break;
859  case '5':
860  $ret = new Rapav_dd_Reconcile();
861  break;
862  case '6' :
863  // For each child we have a Rapav_dd_Account
864  $ret = new Rapav_dd_Account();
865  break;
866  default:
867  throw new Exception("Type inconnu");
868  }
869 
870  $ret->from_array($p_array);
871  $ret->ddr_amount = 0; // cannot be null
872  return $ret;
873  }
$ret
handle the param_detail type Compute
handle the param_detail type Account The type_sum_account gives the type of total ...
handle the param_detail type Account The type_sum_account gives the type of total ...
handle the param_detail type Account_Tva The t_id gives the type of total
Rapav_Declaration_Detail::from_array (   $p_array)
inherited

the p_array contains a row from formulaire_param_detail it will be copied into this->form.

Parameters
type$p_arraymatch formulaire_param_detail table structure

Definition at line 880 of file class_rapav_declaration.php.

881  {
882  $this->form = new Formulaire_Param_Detail();
883  $attribute = explode(',', 'fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail,with_tmp_val,type_sum_account,operation_pcm_val,jrn_def_id,date_paid');
884  foreach ($attribute as $e)
885  {
886  $this->form->$e = $p_array[$e];
887  }
888  }

The documentation for this class was generated from the following file: