Exemplo n.º 1
0
        $ask_pay = 0;
        $p_array['ledger_type'] = 'ODS';
        $Ledger->type = 'ODS';
        break;
    case 'ALL':
        $Ledger = new Acc_Ledger($cn, 0);
        $ask_pay = 0;
        $p_array['ledger_type'] = 'ALL';
        $Ledger->type = 'ALL';
        break;
    case 'VEN':
        $Ledger = new Acc_Ledger_Sold($cn, 0);
        $ask_pay = 1;
        break;
    case 'FIN':
        $Ledger = new Acc_Ledger_Fin($cn, 0);
        $ask_pay = 0;
        break;
}
echo '<div class="content">';
// Check privilege
$p_jrn = HtmlInput::default_value_request("p_jrn", -1);
if (isset($_REQUEST['p_jrn']) && $g_user->check_jrn($_REQUEST['p_jrn']) == 'X') {
    NoAccess();
    exit - 1;
}
$Ledger->id = $p_jrn;
echo $Ledger->display_search_form();
//------------------------------
// UPdate the payment
//------------------------------
Exemplo n.º 2
0
 */
// Copyright Author Dany De Bontridder danydb@aevalys.eu
/**\file
 *
 *
 * \brief reconcile operation
 *
 */
if (!defined('ALLOWED')) {
    die('Appel direct ne sont pas permis');
}
global $g_failed, $g_succeed;
require_once NOALYSS_INCLUDE . '/class_acc_ledger_fin.php';
bcscale(2);
echo '<div class="content">';
$Ledger = new Acc_Ledger_Fin($cn, 0);
if (!isset($_REQUEST['p_jrn'])) {
    $a = $Ledger->get_first('fin');
    $Ledger->id = $a['jrn_def_id'];
} else {
    $Ledger->id = $_REQUEST['p_jrn'];
}
$jrn_priv = $g_user->get_ledger_access($Ledger->id);
if (isset($_GET["p_jrn"]) && $jrn_priv == "X") {
    NoAccess();
    return;
}
//-------------------------
// save
//-------------------------
if (isset($_POST['save'])) {
Exemplo n.º 3
0
 /**
 * @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;
 }
Exemplo n.º 4
0
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
// Copyright Author Dany De Bontridder danydb@aevalys.eu
/*!\file
 * \brief this file is to be included to handle the financial ledger
 */
if (!defined('ALLOWED')) {
    die('Appel direct ne sont pas permis');
}
require_once NOALYSS_INCLUDE . '/class_acc_ledger_fin.php';
require_once NOALYSS_INCLUDE . '/class_ipopup.php';
global $g_user, $g_parameter;
$gDossier = dossier::id();
$cn = new Database(dossier::id());
$menu_action = "?ledger_type=fin&ac=" . $_REQUEST['ac'] . "&" . dossier::get();
$Ledger = new Acc_Ledger_Fin($cn, 0);
//--------------------------------------------------------------------------------
// Encode a new financial operation
//--------------------------------------------------------------------------------
if (isset($_REQUEST['p_jrn'])) {
    $Ledger->id = $_REQUEST['p_jrn'];
} else {
    $def_ledger = $Ledger->get_first('fin');
    if (empty($def_ledger)) {
        exit('Pas de journal disponible');
    }
    $Ledger->id = $def_ledger['jrn_def_id'];
}
$jrn_priv = $g_user->get_ledger_access($Ledger->id);
// Check privilege
if (isset($_REQUEST['p_jrn']) && $jrn_priv == 'X') {
Exemplo n.º 5
0
        require_once NOALYSS_INCLUDE . '/class_acc_ledger_fin.php';
        $ledger = new Acc_Ledger_Fin($cn, $_GET['p_jrn']);
        $html = $ledger->get_last_date();
        $html = escape_xml($html);
        header('Content-type: text/xml; charset=UTF-8');
        echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
<code>e_date</code>
<value>{$html}</value>
</data>
EOF;
        break;
    case 'bkname':
        require_once NOALYSS_INCLUDE . '/class_acc_ledger_fin.php';
        $ledger = new Acc_Ledger_Fin($cn, $_GET['p_jrn']);
        $html = $ledger->get_bank_name();
        $html = escape_xml($html);
        header('Content-type: text/xml; charset=UTF-8');
        echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
<code>bkname</code>
<value>{$html}</value>
</data>
EOF;
        break;
        // display new calendar
    // display new calendar
    case 'cal':
        require_once NOALYSS_INCLUDE . '/class_calendar.php';
 /**
  * @covers Acc_Ledger_Fin::get_bank
  * @todo   Implement testGet_bank().
  */
 public function testGet_bank()
 {
     $this->assertEquals(27, $this->object->get_bank());
 }
Exemplo n.º 7
0
 public function insert($p_array = null)
 {
     global $g_parameter;
     extract($p_array);
     $this->verify($p_array);
     $group = $this->db->get_next_seq("s_oa_group");
     /* for analytic */
     $seq = $this->db->get_next_seq('s_grpt');
     $this->id = $p_jrn;
     $internal = $this->compute_internal_code($seq);
     $this->internal = $internal;
     $oPeriode = new Periode($this->db);
     $check_periode = $this->check_periode();
     if ($check_periode == true) {
         $tperiode = $period;
     } else {
         $tperiode = $oPeriode->find_periode($e_date);
     }
     $cust = new Fiche($this->db);
     $cust->get_by_qcode($e_client);
     $sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
     // if 2 accounts, take only the debit one for the customer
     //
     if (strpos($sposte, ',') != 0) {
         $array = explode(',', $sposte);
         $poste = $array[0];
     } else {
         $poste = $sposte;
     }
     bcscale(4);
     try {
         $tot_amount = 0;
         $tot_tva = 0;
         $tot_debit = 0;
         $this->db->start();
         $tva = array();
         /* Save all the items without vat */
         for ($i = 0; $i < $nb_item; $i++) {
             $n_both = 0;
             if (strlen(trim(${'e_march' . $i})) == 0) {
                 continue;
             }
             /* First we save all the items without vat */
             $fiche = new Fiche($this->db);
             $fiche->get_by_qcode(${"e_march" . $i});
             $amount = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
             $tot_amount = round(bcadd($tot_amount, $amount), 2);
             $acc_operation = new Acc_Operation($this->db);
             $acc_operation->date = $e_date;
             $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
             // if 2 accounts, take only the credit one
             if (strpos($sposte, ',') != 0) {
                 $array = explode(',', $sposte);
                 $poste_val = $array[1];
             } else {
                 $poste_val = $sposte;
             }
             $acc_operation->poste = $poste_val;
             $acc_operation->amount = $amount;
             $acc_operation->grpt = $seq;
             $acc_operation->jrn = $p_jrn;
             $acc_operation->type = 'c';
             $acc_operation->periode = $tperiode;
             if ($g_parameter->MY_UPDLAB == 'Y') {
                 $acc_operation->desc = strip_tags(${"e_march" . $i . "_label"});
             } else {
                 $acc_operation->desc = null;
             }
             $acc_operation->qcode = ${"e_march" . $i};
             if ($amount < 0) {
                 $tot_debit = bcadd($tot_debit, abs($amount));
             }
             $j_id = $acc_operation->insert_jrnx();
             if ($g_parameter->MY_TVA_USE == 'Y') {
                 /* Compute sum vat */
                 $oTva = new Acc_Tva($this->db);
                 $idx_tva = ${'e_march' . $i . '_tva_id'};
                 $tva_item = ${'e_march' . $i . '_tva_amount'};
                 $oTva->set_parameter("id", $idx_tva);
                 $oTva->load();
                 /* if empty then we need to compute it */
                 if (trim($tva_item) == '' || ${'e_march' . $i . '_tva_amount'} == 0) {
                     /* retrieve tva */
                     $l = new Acc_Tva($this->db, $idx_tva);
                     $l->load();
                     $tva_item = bcmul($amount, $l->get_parameter('rate'));
                 }
                 if (isset($tva[$idx_tva])) {
                     $tva[$idx_tva] += $tva_item;
                 } else {
                     $tva[$idx_tva] = $tva_item;
                 }
                 if ($oTva->get_parameter("both_side") == 0) {
                     $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
                 } else {
                     $n_both = $tva_item;
                     if ($n_both < 0) {
                         $tot_debit = bcadd($tot_debit, abs($n_both));
                     }
                 }
             }
             /* Save the stock */
             /* if the quantity is < 0 then the stock increase (return of
              *  material)
              */
             $nNeg = ${"e_quant" . $i} < 0 ? -1 : 1;
             // always save quantity but in withStock we can find
             // what card need a stock management
             if ($g_parameter->MY_STOCK = 'Y' && isset($repo)) {
                 $dir = ${'e_quant' . $i} < 0 ? 'd' : 'c';
                 Stock_Goods::insert_goods($this->db, array('j_id' => $j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 'dir' => $dir, 'repo' => $repo));
             }
             if ($g_parameter->MY_ANALYTIC != "nu") {
                 // for each item, insert into operation_analytique */
                 $op = new Anc_Operation($this->db);
                 $op->oa_group = $group;
                 $op->j_id = $j_id;
                 $op->oa_date = $e_date;
                 $op->oa_debit = 'f';
                 $op->oa_description = sql_string($e_comm);
                 $op->save_form_plan($_POST, $i, $j_id);
             }
             if ($g_parameter->MY_TVA_USE == 'Y') {
                 /* save into quant_sold */
                 $r = $this->db->exec_sql("select insert_quant_sold (\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9)", array(null, $j_id, ${'e_march' . $i}, ${'e_quant' . $i}, round($amount, 2), $tva_item, $idx_tva, $e_client, $n_both));
             } else {
                 $r = $this->db->exec_sql("select insert_quant_sold (\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9) ", array(null, $j_id, ${'e_march' . $i}, ${'e_quant' . $i}, $amount, 0, null, $e_client, 0));
             }
             // if ( $g_parameter->MY_TVA_USE=='Y') {
         }
         // end loop : save all items
         /*  save total customer */
         $cust_amount = bcadd($tot_amount, $tot_tva);
         $acc_operation = new Acc_Operation($this->db);
         $acc_operation->date = $e_date;
         $acc_operation->poste = $poste;
         $acc_operation->amount = $cust_amount;
         $acc_operation->grpt = $seq;
         $acc_operation->jrn = $p_jrn;
         $acc_operation->type = 'd';
         $acc_operation->periode = $tperiode;
         $acc_operation->qcode = ${"e_client"};
         if ($cust_amount > 0) {
             $tot_debit = bcadd($tot_debit, $cust_amount);
         }
         $let_tiers = $acc_operation->insert_jrnx();
         /** save all vat
          * $i contains the tva_id and value contains the vat amount
          * if if ($g_parameter->MY_TVA_USE == 'Y' )
          */
         if ($g_parameter->MY_TVA_USE == 'Y') {
             foreach ($tva as $i => $value) {
                 $oTva = new Acc_Tva($this->db);
                 $oTva->set_parameter('id', $i);
                 $oTva->load();
                 $poste_vat = $oTva->get_side('c');
                 $cust_amount = bcadd($tot_amount, $tot_tva);
                 $acc_operation = new Acc_Operation($this->db);
                 $acc_operation->date = $e_date;
                 $acc_operation->poste = $poste_vat;
                 $acc_operation->amount = $value;
                 $acc_operation->grpt = $seq;
                 $acc_operation->jrn = $p_jrn;
                 $acc_operation->type = 'c';
                 $acc_operation->periode = $tperiode;
                 if ($value < 0) {
                     $tot_debit = bcadd($tot_debit, abs($value));
                 }
                 $acc_operation->insert_jrnx();
                 // if TVA is on both side, we deduce it immediately
                 if ($oTva->get_parameter("both_side") == 1) {
                     $poste_vat = $oTva->get_side('d');
                     $cust_amount = bcadd($tot_amount, $tot_tva);
                     $acc_operation = new Acc_Operation($this->db);
                     $acc_operation->date = $e_date;
                     $acc_operation->poste = $poste_vat;
                     $acc_operation->amount = $value;
                     $acc_operation->grpt = $seq;
                     $acc_operation->jrn = $p_jrn;
                     $acc_operation->type = 'd';
                     $acc_operation->periode = $tperiode;
                     $acc_operation->insert_jrnx();
                     $tot_debit = bcadd($tot_debit, $value);
                     $n_both = $value;
                 }
             }
         }
         // if ($g_parameter->MY_TVA_USE=='Y')
         /* insert into jrn */
         $acc_operation = new Acc_Operation($this->db);
         $acc_operation->date = $e_date;
         $acc_operation->echeance = $e_ech;
         $acc_operation->amount = abs(round($tot_debit, 2));
         $acc_operation->desc = $e_comm;
         $acc_operation->grpt = $seq;
         $acc_operation->jrn = $p_jrn;
         $acc_operation->periode = $tperiode;
         $acc_operation->pj = $e_pj;
         $acc_operation->mt = $mt;
         $this->jr_id = $acc_operation->insert_jrn();
         $this->pj = $acc_operation->set_pj();
         /*             * = e_pj then do not increment sequence */
         /* and e_pj is not null */
         if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) {
             $this->inc_seq_pj();
         }
         $this->db->exec_sql("update jrn set jr_internal='" . $internal . "' where " . " jr_grpt_id = " . $seq);
         /* update quant_sold */
         $this->db->exec_sql('update quant_sold set qs_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)', array($internal, $seq));
         /* Save the attachment or generate doc */
         if (isset($_FILES['pj'])) {
             if (strlen(trim($_FILES['pj']['name'])) != 0) {
                 $this->db->save_upload_document($seq);
             } else {
                 /* Generate an invoice and save it into the database */
                 if (isset($_POST['gen_invoice'])) {
                     $file = $this->create_document($internal, $p_array);
                     $this->doc = '<A class="line" HREF="show_pj.php?' . dossier::get() . '&jr_grpt_id=' . $seq . '&jrn=' . $this->id . '">' . $file . '</A>';
                 }
             }
         }
         //----------------------------------------
         // Save the payer
         //----------------------------------------
         if ($e_mp != 0) {
             /* mp */
             $mp = new Acc_Payment($this->db, $e_mp);
             $mp->load();
             /* fiche */
             $fqcode = ${'e_mp_qcode_' . $e_mp};
             $acfiche = new Fiche($this->db);
             $acfiche->get_by_qcode($fqcode);
             /* jrnx */
             $acseq = $this->db->get_next_seq('s_grpt');
             $acjrn = new Acc_Ledger($this->db, $mp->get_parameter('ledger_target'));
             $acinternal = $acjrn->compute_internal_code($acseq);
             /* Insert paid by  */
             $acc_pay = new Acc_Operation($this->db);
             $acc_pay->date = $e_date;
             /* get the account and explode if necessary */
             $sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
             // if 2 accounts, take only the debit one for customer
             if (strpos($sposte, ',') != 0) {
                 $array = explode(',', $sposte);
                 $poste_val = $array[0];
             } else {
                 $poste_val = $sposte;
             }
             $famount = bcsub($cust_amount, $acompte);
             $acc_pay->poste = $poste_val;
             $acc_pay->qcode = $fqcode;
             $acc_pay->amount = abs(round($famount, 2));
             $acc_pay->desc = null;
             $acc_pay->grpt = $acseq;
             $acc_pay->jrn = $mp->get_parameter('ledger_target');
             $acc_pay->periode = $tperiode;
             $acc_pay->type = $famount >= 0 ? 'd' : 'c';
             $acc_pay->insert_jrnx();
             /* Insert supplier  */
             $acc_pay = new Acc_Operation($this->db);
             $acc_pay->date = $e_date;
             $acc_pay->poste = $poste;
             $acc_pay->qcode = $e_client;
             $acc_pay->amount = abs(round($famount, 2));
             $acc_pay->desc = null;
             $acc_pay->grpt = $acseq;
             $acc_pay->jrn = $mp->get_parameter('ledger_target');
             $acc_pay->periode = $tperiode;
             $acc_pay->type = $famount >= 0 ? 'c' : 'd';
             $let_other = $acc_pay->insert_jrnx();
             /* insert into jrn */
             $acc_pay->mt = $mt;
             $acjrn->grpt_id = $acseq;
             $acc_pay->desc = !isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0 ? $e_comm : $e_comm_paiement;
             $mp_jr_id = $acc_pay->insert_jrn();
             $acjrn->update_internal_code($acinternal);
             $r1 = $this->get_id($internal);
             $r2 = $this->get_id($acinternal);
             /*
              * add lettering
              */
             $oletter = new Lettering($this->db);
             $oletter->insert_couple($let_tiers, $let_other);
             /* set the flag paid */
             $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=\$1", array($r1));
             /* Reconcialiation */
             $rec = new Acc_Reconciliation($this->db);
             $rec->set_jr_id($r1);
             $rec->insert($r2);
             /*
              * save also into quant_fin
              */
             /* get ledger property */
             $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
             $prop = $ledger->get_propertie();
             /* if ledger is FIN then insert into quant_fin */
             if ($prop['jrn_def_type'] == 'FIN') {
                 $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1));
             }
         }
     } catch (Exception $e) {
         echo '<span class="error">' . 'Erreur dans l\'enregistrement ' . __FILE__ . ':' . __LINE__ . ' ' . $e->getMessage();
         echo $e->getTrace();
         $this->db->rollback();
         throw new Exception($e);
     }
     $this->db->commit();
     return $internal;
 }