[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpcompta-dev] r288 - trunk/coprop/include
From: |
phpcompta-dev |
Subject: |
[Phpcompta-dev] r288 - trunk/coprop/include |
Date: |
Fri, 13 Jan 2012 15:29:06 +0100 (CET) |
Author: danydb
Date: 2012-01-13 15:29:05 +0100 (Fri, 13 Jan 2012)
New Revision: 288
Added:
trunk/coprop/include/class_copro_appel_fond_detail.php
Modified:
trunk/coprop/include/appel_fond.inc.php
trunk/coprop/include/class_budget.php
trunk/coprop/include/class_copro_key.php
trunk/coprop/include/class_coprop_appel_fond.php
Log:
Appel de fond : calcul et sauve dans table
Modified: trunk/coprop/include/appel_fond.inc.php
===================================================================
--- trunk/coprop/include/appel_fond.inc.php 2012-01-13 11:01:38 UTC (rev
287)
+++ trunk/coprop/include/appel_fond.inc.php 2012-01-13 14:29:05 UTC (rev
288)
@@ -34,23 +34,34 @@
// Demande génération
if (isset($calc))
{
+ try
+ {
+
// Génére écriture comptable dans journal choisi
- switch ($aft)
+ switch ($aft)
+ {
+ case -1:
+ throw new Exception("Choississez le type de calcul");
+ break;
+ case 1:
+ $appel_fond = new Coprop_Appel_Fond();
+ $error = $appel_fond->compute_budget($_GET);
+ break;
+ case 2:
+ $appel_fond = new Coprop_Appel_Fond();
+ $error = $appel_fond->compute_amount($_GET);
+ break;
+ }
+
+ $appel_fond->display_ledger();
+
+
+ exit();
+ }
+ catch (Exception $e)
{
- case -1:
- $error = 1;
- alert("Choississez le type de calcul");
- break;
- case 1:
- $appel_fond=new Coprop_Appel_Fond();
- $error=$appel_fond->compute_budget($_GET);
- break;
- case 2:
- $appel_fond=new Coprop_Appel_Fond();
- $error=$appel_fond->compute_amount($_GET);
- break;
+ alert($e->getMessage());
}
- if ($error == 0) exit();
}
// Montre écran confirmation
@@ -127,7 +138,7 @@
echo '<form method="get">';
-echo HtmlInput::request_to_hidden('ac', 'plugin_code', 'sa');
+echo HtmlInput::request_to_hidden(array('ac', 'plugin_code', 'sa'));
require_once 'template/appel_fond.php';
echo HtmlInput::submit('calc', "Calculer");
echo '</form>';
Modified: trunk/coprop/include/class_budget.php
===================================================================
--- trunk/coprop/include/class_budget.php 2012-01-13 11:01:38 UTC (rev
287)
+++ trunk/coprop/include/class_budget.php 2012-01-13 14:29:05 UTC (rev
288)
@@ -311,5 +311,12 @@
}
}
+ function get_detail()
+ {
+ global $cn;
+ $array=$cn->get_array("select * from coprop.budget_detail where
b_id=$1",
+ array($this->b_id));
+ return $array;
+ }
}
?>
Added: trunk/coprop/include/class_copro_appel_fond_detail.php
===================================================================
--- trunk/coprop/include/class_copro_appel_fond_detail.php
(rev 0)
+++ trunk/coprop/include/class_copro_appel_fond_detail.php 2012-01-13
14:29:05 UTC (rev 288)
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * @brief manage the table coprop.appel_fond_detail
+ */
+class Copro_Appel_Fond_Detail
+{
+ function insert()
+ {
+ global $cn;
+ $this->afd_id=$cn->get_value("insert into coprop.appel_fond_detail
+ (af_id,lot_id,key_id,afd_amount,key_tantieme,lot_tantieme)
+ values ($1,$2,$3,$4,$5,$6) returning afd_id",
+ array(
+ $this->af_id, //1
+ $this->lot_id, //2
+ $this->key_id, //3
+ $this->afd_amount, //4
+ $this->key_tantieme, //5
+ $this->lot_tantieme)); //6
+ }
+}
+?>
Modified: trunk/coprop/include/class_copro_key.php
===================================================================
--- trunk/coprop/include/class_copro_key.php 2012-01-13 11:01:38 UTC (rev
287)
+++ trunk/coprop/include/class_copro_key.php 2012-01-13 14:29:05 UTC (rev
288)
@@ -95,6 +95,25 @@
echo $exc->getTraceAsString();
}
}
+ function load()
+ {
+ global $cn;
+ $array=$cn->get_array("select * from coprop.clef_repartition where
+ cr_id=$1",$this->cr_id);
+ if ( $cn->count() == 1 )
+ {
+ foreach ( array("cr_id","cr_name","cr_note","cr_tantieme") as
$k=>$e) {
+ $this->$e=$array[0][$e];
+ }
+ }
+ }
+ function get_detail()
+ {
+ global $cn;
+ $array=$cn->get_array("select * from coprop.clef_repartition_detail
+ where cr_id=$1",array($this->cr_id));
+ return $array;
+ }
}
Modified: trunk/coprop/include/class_coprop_appel_fond.php
===================================================================
--- trunk/coprop/include/class_coprop_appel_fond.php 2012-01-13 11:01:38 UTC
(rev 287)
+++ trunk/coprop/include/class_coprop_appel_fond.php 2012-01-13 14:29:05 UTC
(rev 288)
@@ -2,7 +2,8 @@
/**
address@hidden calcul appel de fond
*/
-
+require_once 'class_copro_key.php';
+require_once 'class_copro_budget.php';
class Coprop_Appel_Fond
{
/**
@@ -16,18 +17,77 @@
$this->exec_sql("delete from coprop.appel_fond where af_confirmed='N'
and tech_per < tech_per - interval '5 hours' )");
// insert new unconfirmed
- $cn->exec_sql("insert into
coprop.appel_fond(af_id,af_date,af_confirmed,af_percent,af_amount,af_card,af_ledger,tech_per)
- values
($1,to_date($2,'DD.MM.YYYY','N',$3,$4,$5,$6,$7,now())",array($this->id,$this->af_date,$this->percent,$this->amount,$this->bud_id,$this->af_card,$this->af_ledger));
+ $cn->exec_sql("insert into
coprop.appel_fond(af_id,af_date,af_confirmed,af_percent,af_amount,af_card,af_ledger,tech_per,b_id,cr_id)
+ values
($1,to_date($2,'DD.MM.YYYY','N',$3,$4,$5,$6,$7,now()),$8",
+
array($this->id,$this->af_date,$this->percent,$this->amount,$this->af_card,$this->af_ledger,$this->b_id,$this->cr_id));
}
+ function compute_key($p_key_id,$p_amount)
+ {
+ global $cn;
+ try
+ {
+ $cn->start();
+ // prend tantieme global
+ $key=new Copro_Key();
+ $key->cr_id=$p_key_id;
+ $key->load();
+
+ bcscale(4);
+ $a_lot=$key->get_detail();
+ for ($i=0;$i<count($a_lot);$i++)
+ {
+ $afd=new Copro_Appel_Fond_Detail();
+ $afd->af_id=$this->id;
+ $afd->lot_id=$a_lot[$i]['lot_fk'];
+ $afd->key_id=$p_key_id;
+ $afd->key_tantieme=$key->cr_tantieme;
+ $afd->lot_tantieme=$a_lot[$i]['crd_amount'];
+
+ $fract=bcsub($key->cr_tantieme,$a_lot[$i]['crd_amount']);
+ $afd->afd_amount=$fract;
+
+ $afd->insert();
+
+ }
+
+ }
+ catch (Exception $exc)
+ {
+ echo $exc->getTraceAsString();
+ $cn->rollback();
+ throw $exc;
+ }
+ }
function compute_amount($p_array)
{
- $this->type="amount";
- $this->amount=0;
- $this->percent=1;
- $this->bud_id=null;
-
- $this->create_key();
+ global $cn;
+ bcscale(2);
+ try
+ {
+ $this->type = "amount";
+ $this->af_amount = $p_array['amount'];
+ $this->cr_id = $p_array['cr_id'];
+ $this->percent = 1;
+ $this->b_id = null;
+ // req date valide
+ if (isDate($p_array['p_date']) == null)
+ throw new Exception('La date est invalide');
+ $this->af_ledger = $p_array['p_jrn'];
+ $this->af_date = $p_array['p_date'];
+ $fiche = new Fiche($cn);
+ $fiche->get_by_qcode($p_array['w_categorie_appel']);
+ // req $fiche->id > 0
+ if ($fiche->id < 1)
+ throw new Exception("La fiche pour l'appel de fond n'existe
pas");
+ $this->af_card = $fiche->id;
+ $this->create_key();
+ $this->compute_key($this->cr_id,$this->af_amount);
+ }
+ catch (Exception $e)
+ {
+ throw ($e);
+ }
}
function compute_budget($p_array)
{
@@ -41,7 +101,7 @@
if ( isDate($p_array['p_date'])==null) throw new Exception('La
date est invalide');
$this->type="budget";
- $this->bud_id=$p_array['b_id'];
+ $this->b_id=$p_array['b_id'];
$this->percent=$p_array['bud_pct'];
$this->af_ledger=$p_array['p_jrn'];
$this->af_date=$p_array['p_date'];
@@ -51,15 +111,38 @@
if ( $fiche->id < 1 ) throw new Exception("La fiche pour l'appel
de fond n'existe pas");
$this->af_card=$fiche->id;
- $tot_bud=$cn->get_value('select b_amount from coprop.budget where
b_id=$1',array($this->bud_id));
+ $tot_bud=$cn->get_value('select b_amount from coprop.budget where
b_id=$1',array($this->b_id));
if ($tot_bud <=0 ) throw new Exception ("Ce budget a un montant
de 0 ");
- $this->amount= bcmul($tot_bud,$this->percent);
+ $this->af_amount= bcmul($tot_bud,$this->percent);
$this->create_key();
+
+ // get all the key of this budget
+ $budget=new Budget();
+ $budget->b_id=$this->b_id;
+
+ $a_detail=$budget->get_detail();
+ bcscale(4);
+
+ // foreach key,
+ for ($i=0;$i<count($a_detail);$i++)
+ {
+ // compute the amount to take
+ $amount=$a_detail[$i]['bt_amount'];
+ $key=$a_detail[$i]['cr_id'];
+
+ // call compute_key
+ $this->compute_key($key, $amount);
+
+ }
} catch (Exception $e)
{
throw ($e);
}
}
+ function display_ledger()
+ {
+
+ }
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpcompta-dev] r288 - trunk/coprop/include,
phpcompta-dev <=