/** * @brief retrieve amount of previous periode * @param $p_to frmo the start of the exercise until $p_to * @return $array with vat, price,other_amount * @note * @see @code array 'price' => string '446.1900' (length=8) 'vat' => string '21.7600' (length=7) 'priv' => string '0.0000' (length=6) 'tva_nd_recup' => string '0.0000' (length=6) 'tva' => array 0 => array 'sum_vat' => string '13.7200' (length=7) 'tva_id' => string '1' (length=1) 1 => array 'sum_vat' => string '8.0400' (length=6) 'tva_id' => string '3' (length=1) 2 => array 'sum_vat' => string '0.0000' (length=6) 'tva_id' => string '4' (length=1) @endcode */ function previous_amount($p_to) { /* get the first periode of exercise */ $periode = new Periode($this->db, $p_to); $exercise = $periode->get_exercice(); list($min, $max) = $periode->get_limit($exercise); // transform min into date $min_date = $min->first_day(); // transform $p_to into date $periode_max = new Periode($this->db, $p_to); $max_date = $periode_max->first_day(); bcscale(2); // min periode if ($this->type == 'ACH') { /* get all amount exclude vat */ $sql = "select coalesce(sum(qp_price),0) as price" . " ,coalesce(sum(qp_vat),0) as vat " . ',coalesce(sum(qp_dep_priv),0) as priv' . ',coalesce(sum(qp_vat_sided),0) as reversed' . ',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd' . ',coalesce(sum(qp_vat_sided),0) as tva_np' . ' from quant_purchase 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'; $array = $this->db->get_array($sql, array($min_date, $max_date, $this->id)); $ret = $array[0]; /* retrieve all vat code */ $array = $this->db->get_array("select coalesce(sum(qp_vat),0) as sum_vat,tva_id\n from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)\n where tva_rate !=0 and j_date >= to_date(\$1,'DD.MM.YYYY') and j_date < to_date(\$2,'DD.MM.YYYY') \n and j_jrn_def = \$3\n group by tva_id", array($min_date, $max_date, $this->id)); $ret['tva'] = $array; } if ($this->type == 'VEN') { /* get all amount exclude vat */ $sql = "select coalesce(sum(qs_price),0) as price" . " ,coalesce(sum(qs_vat),0) as vat " . ',0 as priv' . ',0 as tva_nd' . ',coalesce(sum(qs_vat_sided),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'; $array = $this->db->get_array($sql, array($min_date, $max_date, $this->id)); $ret = $array[0]; /* retrieve all vat code */ $array = $this->db->get_array("select coalesce(sum(qs_vat),0) as sum_vat,tva_id\n from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)\n where tva_rate !=0 and\n j_date >= to_date(\$1,'DD.MM.YYYY') and j_date < to_date(\$2,'DD.MM.YYYY') \n and j_jrn_def = \$3\n group by tva_id", array($min_date, $max_date, $this->id)); $ret['tva'] = $array; } if ($this->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); /*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); $saldo = $bank_card->get_bk_balance($cond); $ret['amount'] = bcsub($saldo['debit'], $saldo['credit']); } return $ret; }
require_once NOALYSS_INCLUDE . '/class_user.php'; require_once NOALYSS_INCLUDE . '/class_dossier.php'; require_once NOALYSS_INCLUDE . '/class_fiche.php'; extract($_GET); /* check the parameters */ foreach (array('j', 'ctl') as $a) { if (!isset(${$a})) { echo "missing {$a}"; return; } } if ($g_user->check_jrn($_GET['j']) == 'X') { return '{"saldo":"0"}'; } /* make a filter on the exercice */ $filter_year = " j_tech_per in (select p_id from parm_periode " . "where p_exercice='" . $g_user->get_exercice() . "')"; $id = $cn->get_value('select jrn_def_bank from jrn_def where jrn_def_id=$1', array($_GET['j'])); $acc = new Fiche($cn, $id); $res = $acc->get_bk_balance($filter_year . " and ( trim(jr_pj_number) != '' and jr_pj_number is not null)"); if (empty($res)) { return '{"saldo":"0"}'; } $solde = $res['solde']; if ($res['debit'] < $res['credit']) { $solde = $solde * -1; } //header("Content-type: text/html; charset: utf8",true); echo '{"saldo":"' . $solde . '"}'; ?>