<A class="mtitle" HREF="?ac=' . $_REQUEST['ac'] . '&see&' . $str_dossier . '">' . _('Liste opérations') . ' </A </td> </tr> </table> </div> </div> '; //---------------------------------------------------------------------- // the pa_id is set // //---------------------------------------------------------------------- if (isset($_GET['see'])) { // Show the list for the period // and exit //----------------------------- $a = new Anc_Operation($cn); echo ' <div class="content" > <form method= "get"> '; echo dossier::hidden(); $hid = new IHidden(); $hid->name = "ac"; $hid->value = $_REQUEST['ac']; echo $hid->input(); $hid->name = "see"; $hid->value = ""; echo $hid->input(); $w = new ISelect(); $w->name = "p_periode"; // filter on the current year
function test_me() { $cn = new Database(dossier::id()); $anco = new Anc_Operation($cn); $j_id = 200; $anco->j_id = $j_id; $array = $anco->get_by_jid($j_id); $a = $anco->to_request($array, 1); echo '<form>'; echo dossier::hidden(); echo HtmlInput::hidden('j_id', $j_id); echo HtmlInput::hidden('test_select', $_REQUEST['test_select']); echo $anco->display_table(1, 15002, 0); echo '<input type="submit" name="save">'; echo '</form>'; if (isset($_REQUEST['save'])) { echo "to_save"; var_dump($_REQUEST); } var_dump($a); }
function load() { $op = new Anc_Operation($this->db); $op->pa_id = $this->pa_id; $array = $op->get_list($this->from, $this->to, $this->from_poste, $this->to_poste); if (!$array) { $this->has_data = 0; } else { $this->has_data = count($array); } return $array; }
$tva_amount_nd = bcadd($q['qp_nd_tva_recup'], $q['qp_nd_tva']); $class = ""; if ($q['qp_vat_sided'] != 0) { $class = ' style="text-decoration:line-through"'; } $row .= td(nbm($tva_amount_nd), 'class="num" ' . $class); $row .= td(nbm($q['qp_vat']), 'class="num" ' . $class); $row .= td(nbm($tvac), 'class="num"'); } $total_tvac = bcadd($total_tvac, $tvac); $total_htva = bcadd($htva, $total_htva); /* Analytic accountancy */ if ($owner->MY_ANALYTIC != "nu") { $poste = $fiche->strAttribut(ATTR_DEF_ACCOUNT); if (preg_match('/^(6|7)/', $poste)) { $anc_op = new Anc_Operation($cn); $anc_op->j_id = $q['j_id']; $anc_op->in_div = $div; echo HtmlInput::hidden('op[]', $anc_op->j_id); /* compute total price */ bcscale(2); $str_anc .= '<tr>'; $str_anc .= td($qcode); $str_anc .= td(nbm($htva)); $str_anc .= $anc_op->display_table(1, $htva, $div); } else { $row .= td(''); } } $class = $e % 2 == 0 ? ' class="even"' : 'class="odd"'; echo tr($row, $class);
$str_anc .= '<th colspan="' . $x . '" style="width:auto;text-align:center">' . _('Compt. Analytique') . '</th>'; /* add hidden variables pa[] to hold the value of pa_id */ $str_anc .= Anc_Plan::hidden($a_anc); } bcscale(2); for ($e = 0; $e < count($detail->det->array); $e++) { $row = ''; $q = $detail->det->array; $fiche = new Fiche($cn); $fiche->get_by_qcode($q[$e]['j_qcode']); /* Analytic accountancy */ if ($owner->MY_ANALYTIC != "nu") { $poste = $fiche->strAttribut(ATTR_DEF_ACCOUNT); if (preg_match('/^(6|7)/', $q[$e]['j_poste'])) { $qcode = $fiche->strAttribut(ATTR_DEF_QUICKCODE); $anc_op = new Anc_Operation($cn); $anc_op->j_id = $q[$e]['j_id']; $anc_op->in_div = $div; $str_anc .= '<tr>'; $str_anc .= td($poste); $str_anc .= td($qcode); $str_anc .= td(nbm($q[$e]['j_montant'])); $str_anc .= '<td>'; $str_anc .= HtmlInput::hidden('op[]', $anc_op->j_id); $montant = $q[$e]['j_debit'] == "t" ? $q[$e]['j_montant'] : bcmul($q[$e]['j_montant'], -1); $str_anc .= $anc_op->display_table(1, $montant, $div); $str_anc .= '</td>'; $str_anc .= '</tr>'; } } }
$input = new IText("e_march" . $q[$e]['j_id'] . "_label", $l_lib); $input->css_size = "100%"; } else { $input = new ISpan("e_march" . $q[$e]['j_id'] . "_label"); $input->value = $l_lib; $hidden = HtmlInput::hidden("j_id[]", $q[$e]['j_id']); } $row .= td($input->input() . $hidden); $montant = td(nbm($q[$e]['j_montant']), 'class="num"'); $row .= $q[$e]['j_debit'] == 't' ? $montant : td(''); $row .= $q[$e]['j_debit'] == 'f' ? $montant : td(''); /* Analytic accountancy */ if ($owner->MY_ANALYTIC != "nu") { if (preg_match('/^(6|7)/', $q[$e]['j_poste'])) { echo HtmlInput::hidden("amount_t" . $amount_idx, $q[$e]['j_montant']); $anc_op = new Anc_Operation($cn); $anc_op->j_id = $q[$e]['j_id']; $anc_op->in_div = $div; $str_anc .= '<tr>'; $str_anc .= HtmlInput::hidden('op[]', $anc_op->j_id); $str_anc .= td($q[$e]['j_qcode']); $str_anc .= td($q[$e]['j_poste']); $str_anc .= td($q[$e]['j_montant']); $str_anc .= $anc_op->display_table(1, $q[$e]['j_montant'], $div); $str_anc .= '</tr>'; $amount_idx++; } else { $row .= td(''); } } $class = $e % 2 == 0 ? ' class="even"' : 'class="odd"';
/** * @brief save the operation into the jrnx,jrn, , * CA and pre_def * @param$p_array * * \return array with [0] = false if failed otherwise true, [1] error * code */ function save($p_array = null) { if ($p_array == null) { throw new Exception('save cannot use a empty array'); } global $g_parameter; extract($p_array); try { $msg = $this->verify($p_array); if (!empty($msg)) { echo $this->display_warning($msg, _("Attention : il vaut mieux utiliser les fiches que les postes comptables ")); } $this->db->start(); $seq = $this->db->get_next_seq('s_grpt'); $internal = $this->compute_internal_code($seq); $group = $this->db->get_next_seq("s_oa_group"); $tot_amount = 0; $tot_deb = 0; $tot_cred = 0; $oPeriode = new Periode($this->db); $check_periode = $this->check_periode(); if ($check_periode == false) { $oPeriode->find_periode($e_date); } else { $oPeriode->id = $period; } $count = 0; for ($i = 0; $i < $nb_item; $i++) { if (!isset(${'qc_' . $i}) && !isset(${'poste' . $i})) { continue; } $acc_op = new Acc_Operation($this->db); $quick_code = ""; // First we save the jrnx if (isset(${'qc_' . $i})) { $qc = new Fiche($this->db); $qc->get_by_qcode(${'qc_' . $i}, false); $sposte = $qc->strAttribut(ATTR_DEF_ACCOUNT); /* if there are 2 accounts take following the deb or cred */ if (strpos($sposte, ',') != 0) { $array = explode(",", $sposte); $poste = isset(${'ck' . $i}) ? $array[0] : $array[1]; } else { $poste = $sposte; if ($poste == '') { throw new Exception(sprintf(_("La fiche %s n'a pas de poste comptable"), ${"qc_" . $i})); } } $quick_code = ${'qc_' . $i}; } else { $poste = ${'poste' . $i}; } $acc_op->date = $e_date; // compute the periode is do not check it if ($check_periode == false) { $acc_op->periode = $oPeriode->p_id; } $acc_op->desc = null; if (strlen(trim(${'ld' . $i})) != 0) { $acc_op->desc = ${'ld' . $i}; } $acc_op->amount = round(${'amount' . $i}, 2); $acc_op->grpt = $seq; $acc_op->poste = $poste; $acc_op->jrn = $this->id; $acc_op->type = isset(${'ck' . $i}) ? 'd' : 'c'; $acc_op->qcode = $quick_code; $j_id = $acc_op->insert_jrnx(); $tot_amount += round($acc_op->amount, 2); $tot_deb += $acc_op->type == 'd' ? $acc_op->amount : 0; $tot_cred += $acc_op->type == 'c' ? $acc_op->amount : 0; if ($g_parameter->MY_ANALYTIC != "nu") { if (preg_match("/^[6,7]+/", $poste) == 1) { // 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 = $acc_op->type == 'd' ? 't' : 'f'; $op->oa_description = $desc; $op->save_form_plan($p_array, $count, $j_id); $count++; } } } // loop for each item $acc_end = new Acc_Operation($this->db); $acc_end->amount = $tot_deb; if ($check_periode == false) { $acc_end->periode = $oPeriode->p_id; } $acc_end->date = $e_date; $acc_end->desc = $desc; $acc_end->grpt = $seq; $acc_end->jrn = $this->id; $acc_end->mt = $mt; $jr_id = $acc_end->insert_jrn(); $this->jr_id = $jr_id; if ($jr_id == false) { throw new Exception(_('Balance incorrecte')); } $acc_end->pj = $e_pj; /* if e_suggest != e_pj then do not increment sequence */ if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) { $this->inc_seq_pj(); } $this->pj = $acc_end->set_pj(); $this->db->exec_sql("update jrn set jr_internal='" . $internal . "' where " . " jr_grpt_id = " . $seq); $this->internal = $internal; // Save now the predef op //------------------------ if (isset($opd_name) && trim($opd_name) != "") { $opd = new Pre_Op_Advanced($this->db); $opd->get_post(); $opd->save(); } if (isset($this->with_concerned) && $this->with_concerned == true) { $orap = new acc_reconciliation($this->db); $orap->jr_id = $jr_id; $orap->insert($jrn_concerned); } /** * Save the file is any */ if (isset($_FILES["pj"])) { $this->db->save_upload_document($seq); } } catch (Exception $a) { throw $a; } catch (Exception $e) { $this->db->rollback(); echo _('OPERATION ANNULEE '); echo '<hr>'; echo __FILE__ . __LINE__ . $e->getMessage(); exit; } $this->db->commit(); return true; }
$rec->insert($rapt); } } } if (isset($_POST['ipaid'])) { $cn->exec_sql("update jrn set jr_rapt='paid' where jr_id=\$1", array($jr_id)); } else { $cn->exec_sql("update jrn set jr_rapt=null where jr_id=\$1", array($jr_id)); } //////////////////////////////////////////////////// // CA ////////////////////////////////////////////////// $owner = new Own($cn); if ($owner->MY_ANALYTIC != "nu" && isset($_POST['op'])) { // for each item, insert into operation_analytique */ $opanc = new Anc_Operation($cn); $opanc->save_update_form($_POST); } ////////////////////////////////////////////////////////////////// //Save other info ////////////////////////////////////////////////////////////////// $op->save_info($_POST['OTHER'], 'OTHER'); $op->save_info($_POST['BON_COMMANDE'], 'BON_COMMANDE'); /////////////////////////////////////////////////////////////////// // Save related ////////////////////////////////////////////////////////////////// $related = HtmlInput::default_value_post("related", "0"); if ($related == "0") { throw new Exception('Parameter not send -> related' . __FILE__ . __LINE__, 10); } $op->insert_related_action($related);
function confirm($p_array, $p_summary = false) { global $g_parameter; extract($p_array); // don't need to verify for a summary if (!$p_summary) { $this->verify($p_array); } $anc = null; // to show a select list for the analytic & VAT USE // if analytic is op (optionnel) there is a blank line bcscale(4); $client = new Fiche($this->db); $client->get_by_qcode($e_client, true); $client_name = $client->getName() . ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' . $client->strAttribut(ATTR_DEF_CP) . ' ' . $client->strAttribut(ATTR_DEF_CITY); $lPeriode = new Periode($this->db); if ($this->check_periode() == true) { $lPeriode->p_id = $period; } else { $lPeriode->find_periode($e_date); } $date_limit = $lPeriode->get_date_limit(); $r = ""; $r .= '<TABLE>'; if ($p_summary) { $jr_id = $this->db->get_value('select jr_id from jrn where jr_internal=$1', array($this->internal)); $r .= "<tr>"; $r .= '<td>'; $r .= _('Détail opération '); $r .= '</td>'; $r .= '<td>'; $r .= sprintf('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>', $jr_id, dossier::id(), $this->internal); $r .= '</td>'; $r .= "</tr>"; } $r .= '<tr>'; if (!$p_summary) { $r .= '<td>' . _('Numéro Pièce') . '</td><td>' . hb($e_pj) . '</td>'; } else { if (strcmp($this->pj, $e_pj) != 0) { $r .= '<td>' . _('Numéro Pièce') . '</td><td>' . hb($this->pj) . '<span class="notice"> ' . _('Attention numéro pièce existante, elle a du être adaptée') . '</span></td>'; } else { $r .= '<td>' . _('Numéro Pièce') . '</td><td>' . hb($this->pj) . '</td>'; } } $r .= '</tr>'; $r .= '<tr>'; $r .= '<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>'; $r .= '</tr>'; $r .= '<tr>'; $r .= '<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>'; $r .= '</tr>'; $r .= '<tr>'; $r .= '<td> ' . _('Période Comptable') . '</td><td> ' . hb($date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>'; $r .= '</tr>'; $r .= '<tr>'; $r .= '<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>'; $r .= '</tr>'; $r .= '<tr>'; $r .= '<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>'; $r .= '</tr>'; $r .= '<tr>'; $r .= '<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>'; $r .= '</tr>'; $r .= '</table>'; $r .= '<h2>' . _('Détail articles vendus') . '</h2>'; $r .= '<p class="decale">'; $r .= '<table class="result" >'; $r .= '<TR>'; $r .= "<th>" . _('Code') . "</th>"; $r .= "<th>" . _('Dénomination') . "</th>"; $r .= "<th style=\"text-align:right\">" . _('prix') . "</th>"; $r .= "<th style=\"text-align:right\">" . _('quantité') . "</th>"; if ($g_parameter->MY_TVA_USE == 'Y') { $r .= "<th style=\"text-align:right\">" . _('tva') . "</th>"; $r .= '<th style="text-align:right"> ' . _('Montant TVA') . '</th>'; $r .= '<th style="text-align:right">' . _('Montant HTVA') . '</th>'; $r .= '<th style="text-align:right">' . _('Montant TVAC') . '</th>'; } else { $r .= '<th style="text-align:right">' . _('Montant') . '</th>'; } /* if we use the AC */ if ($g_parameter->MY_ANALYTIC != 'nu') { $anc = new Anc_Plan($this->db); $a_anc = $anc->get_list(); $x = count($a_anc); /* set the width of the col */ $r .= '<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>'; /* add hidden variables pa[] to hold the value of pa_id */ $r .= Anc_Plan::hidden($a_anc); } $r .= '</tr>'; $tot_amount = 0.0; $tot_tva = 0.0; for ($i = 0; $i < $nb_item; $i++) { if (strlen(trim(${"e_march" . $i})) == 0) { continue; } /* retrieve information for card */ $fiche = new Fiche($this->db); $fiche->get_by_qcode(${"e_march" . $i}); if ($g_parameter->MY_UPDLAB == 'Y') { $fiche_name = h(${"e_march" . $i . "_label"}); } else { $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME); } if ($g_parameter->MY_TVA_USE == 'Y') { $oTva = new Acc_Tva($this->db); $idx_tva = ${"e_march" . $i . "_tva_id"}; $oTva->set_parameter('id', $idx_tva); $oTva->load(); } $op = new Acc_Compute(); $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i}); $op->set_parameter("amount", $amount); if ($g_parameter->MY_TVA_USE == 'Y') { $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate')); $op->compute_vat(); $tva_computed = $op->get_parameter('amount_vat'); $tva_item = ${"e_march" . $i . "_tva_amount"}; if (isset($tva[$idx_tva])) { $tva[$idx_tva] += $tva_item; } else { $tva[$idx_tva] = $tva_item; } $tot_tva = round(bcadd($tva_item, $tot_tva), 2); } $tot_amount = round(bcadd($tot_amount, $amount), 2); $r .= '<tr>'; $r .= '<td>'; $r .= ${"e_march" . $i}; $r .= '</td>'; $r .= '<TD style="border-bottom:1px dotted grey;">'; $r .= $fiche_name; $r .= '</td>'; $r .= '<td class="num">'; $r .= nbm(${"e_march" . $i . "_price"}); $r .= '</td>'; $r .= '<td class="num">'; $r .= nbm(${"e_quant" . $i}); $r .= '</td>'; $both_side = 0; if ($g_parameter->MY_TVA_USE == 'Y') { $r .= '<td class="num">'; $r .= $oTva->get_parameter('label'); $r .= '</td>'; $both_side = $oTva->get_parameter("both_side"); /* warning if tva_computed and given are not the same */ if (bcsub($tva_item, $tva_computed) != 0 && !($tva_item == 0 && $both_side == 1)) { $r .= '<td style="background-color:red" class="num">'; $r .= HtmlInput::infobulle(28); $r .= '<a href="#" class="error" style="display:inline" title="' . _("Attention Différence entre TVA calculée et donnée") . '">' . nbm($tva_item) . '<a>'; } else { $r .= '<td class="num">'; $r .= nbm($tva_item); } $r .= '</td>'; $r .= '<td class="num">'; $r .= nbm($amount); $r .= '</td>'; $tot_row = bcadd($tva_item, $amount); $r .= td(nbm($tot_row), 'class="num"'); } else { $r .= '<td class="num">'; $r .= nbm($amount); $r .= '</td>'; } // encode the pa if ($g_parameter->MY_ANALYTIC != 'nu') { // use of AA // show form $anc_op = new Anc_Operation($this->db); $null = $g_parameter->MY_ANALYTIC == 'op' ? 1 : 0; $r .= '<td>'; $p_mode = $p_summary == false ? 1 : 0; $p_array['pa_id'] = $a_anc; /* op is the operation it contains either a sequence or a jrnx.j_id */ $r .= HtmlInput::hidden('op[]=', $i); $r .= $anc_op->display_form_plan($p_array, $null, $p_mode, $i, $amount); $r .= '</td>'; } $r .= '</tr>'; } // end loop item // // Add the sum $decalage = $g_parameter->MY_TVA_USE == 'Y' ? '<td></td><td></td><td></td><td></td>' : '<td></td>'; $tot = round(bcadd($tot_amount, $tot_tva), 2); $tot_tva = nbm($tot_tva); $tot = nbm($tot); $str_tot = _('Totaux'); $tot_amount = nbm($tot_amount); $r .= <<<EOF <tr class="highlight"> {$decalage} <td> {$str_tot} </td> <td class="num"> {$tot_tva} </td> <td class="num"> {$tot_amount} </td> <td class="num"> {$tot} </td> EOF; $r .= '</table>'; $r .= '</p>'; if ($g_parameter->MY_ANALYTIC != 'nu' && !$p_summary) { // use of AA $r .= '<input type="button" class="button" value="' . _('Vérifiez Imputation Analytique') . '" onClick="verify_ca(\'\');">'; } $r .= !$p_summary ? '<div id="total_div_id" >' : '<div>'; $r .= '<h2>Totaux</h2>'; /* use VAT */ if ($g_parameter->MY_TVA_USE == 'Y') { $r .= '<table>'; $r .= '<tr><td>Total HTVA</td>'; $r .= td(hb($tot_amount), 'class="num"'); foreach ($tva as $i => $value) { $oTva->set_parameter('id', $i); $oTva->load(); $r .= '<tr><td> TVA ' . $oTva->get_parameter('label') . '</td>'; $r .= td(hb(nbm($tva[$i])), 'class="num"'); } $r .= '<tr>' . td(_('Total TVA')) . td(hb($tot_tva), 'class="num"'); $r .= '<tr>' . td(_('Total TVAC')) . td(hb($tot), 'class="num"'); $r .= '</table>'; } else { $r .= '<br>Total ' . hb($tot); } $r .= '</div>'; /* Add hidden */ $r .= HtmlInput::hidden('e_client', $e_client); $r .= HtmlInput::hidden('nb_item', $nb_item); $r .= HtmlInput::hidden('p_jrn', $p_jrn); $mt = microtime(true); $r .= HtmlInput::hidden('mt', $mt); if (isset($period)) { $r .= HtmlInput::hidden('period', $period); } /* \todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */ $r .= HtmlInput::hidden('e_comm', $e_comm); $r .= HtmlInput::hidden('e_date', $e_date); $r .= HtmlInput::hidden('e_ech', $e_ech); $r .= HtmlInput::hidden('e_pj', $e_pj); $r .= HtmlInput::hidden('e_pj_suggest', $e_pj_suggest); $e_mp = isset($e_mp) ? $e_mp : 0; $r .= HtmlInput::hidden('e_mp', $e_mp); if (isset($repo)) { // Show the available repository $r .= $this->select_depot($p_summary, $repo); } /* if the paymethod is not 0 and if a quick code is given */ if ($e_mp != 0 && strlen(trim(${'e_mp_qcode_' . $e_mp})) != 0) { $r .= HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp}); $r .= HtmlInput::hidden('acompte', $acompte); $r .= HtmlInput::hidden('e_comm_paiement', $e_comm_paiement); /* needed for generating a invoice */ $r .= HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp}); $fname = new Fiche($this->db); $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp}); $r .= '<h2>' . "Payé par " . ${'e_mp_qcode_' . $e_mp} . " " . $fname->getName() . '</h2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' . _('Libellé :') . h($e_comm_paiement); $r .= '<br>'; } $r .= HtmlInput::hidden('jrn_type', $jrn_type); for ($i = 0; $i < $nb_item; $i++) { $r .= HtmlInput::hidden("e_march" . $i, ${"e_march" . $i}); if (isset(${"e_march" . $i . "_label"})) { $r .= HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"}); } $r .= HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"}); if ($g_parameter->MY_TVA_USE == 'Y') { $r .= HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"}); $r .= HtmlInput::hidden("e_march" . $i . "_tva_amount", ${"e_march" . $i . "_tva_amount"}); } $r .= HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i}); } return $r; }
/** * @brief Call the Anc_Operation::display_form_plan with the right amounts. * This function compute the array and amount to pass to the Anc_Operation::display_form_plan * and replace the current table of activity with the value computed from the key. * * @global $cn database connection * @param $p_target Table to be replaced * @param $p_amount amount to distribute among activities */ function fill_table($p_target, $p_amount) { global $cn; /* number is the index of the plan, he's computed from p_target */ $number = preg_replace('/det[0-9]/', '', $p_target); $number = str_replace('t', '', $number); $number = str_replace('popup', '', $number); $op[$number] = $p_amount; $array['op'] = $op; $a_plan = $cn->get_array('select pa_id from plan_analytique order by pa_id'); for ($i = 0; $i < count($a_plan); $i++) { $array['pa_id'][$i] = $a_plan[$i]['pa_id']; } $a_poste = $cn->get_array('select po_id,ke_percent,pa_id,ke_row from key_distribution_activity join key_distribution_detail using (ke_id) where kd_id=$1 order by ke_row,pa_id', array($this->key->getp('id'))); for ($i = 0; $i < count($a_poste); $i++) { $hplan[$number][$i] = $a_poste[$i]['po_id'] == null ? -1 : $a_poste[$i]['po_id']; } $array['hplan'] = $hplan; $a_amount = $cn->get_array("select distinct ke_row,ke_percent \n from key_distribution_activity \n join key_distribution_detail using (ke_id) \n where\n kd_id=\$1\n and pa_id=\$2\n order by ke_row", array($this->key->getp('id'), $a_plan[0]['pa_id'])); bcscale(2); for ($i = 0; $i < count($a_amount); $i++) { $val[$number][$i] = bcmul($p_amount, $a_amount[$i]['ke_percent']) / 100; } $array['val'] = $val; $anc_operation = new Anc_Operation($cn); echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount, '', false); }
public function insert($p_array = null) { global $g_parameter; bcscale(2); $internal_code = ""; $oid = 0; extract($p_array); $ret = ''; // Debit = banque $bank_id = $this->get_bank(); $fBank = new Fiche($this->db, $bank_id); $e_bank_account = $fBank->strAttribut(ATTR_DEF_QUICKCODE); // Get the saldo $pPeriode = new Periode($this->db); $sposte = $fBank->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; } $acc_account = new Acc_Account_Ledger($this->db, $poste_val); // If date = deposit date if ($chdate == 1) { if ($this->check_periode() == true) { $pPeriode->p_id = $periode; } else { $pPeriode->find_periode($e_date); } $exercice = $pPeriode->get_exercice(); $filter_year = " j_tech_per in (select p_id from parm_periode where p_exercice='" . $exercice . "')"; $asolde = $acc_account->get_solde_detail($filter_year); $deb = $asolde['debit']; $cred = $asolde['credit']; $solde = bcsub($deb, $cred); $new_solde = $solde; } try { $this->db->start(); $amount = 0.0; $idx_operation = 0; $ret = '<table class="result" >'; $ret .= tr(th('Date') . th('n° interne') . th('Quick Code') . th('Nom') . th('Libellé') . th('Montant', ' style="text-align:right"')); // Credit = goods $get_solde = true; for ($i = 0; $i < $nb_item; $i++) { // insert it into the database // and quit the loop ? if (strlen(trim(${"e_other{$i}"})) == 0) { continue; } if ($chdate == 2) { $e_date = ${'dateop' . $i}; } // if date is date of operation if ($chdate == 2 && $get_solde) { $get_solde = false; if ($this->check_periode() == true) { $pPeriode->p_id = $periode; } else { $pPeriode->find_periode($e_date); } $exercice = $pPeriode->get_exercice(); $filter_year = " j_tech_per in (select p_id from parm_periode where p_exercice='" . $exercice . "')"; $solde = $acc_account->get_solde($filter_year); $new_solde = $solde; } $fPoste = new Fiche($this->db); $fPoste->get_by_qcode(${"e_other{$i}"}); // round it ${"e_other{$i}" . "_amount"} = round(${"e_other{$i}" . "_amount"}, 2); $amount += ${"e_other{$i}" . "_amount"}; // Record a line for the bank // Compute the j_grpt $seq = $this->db->get_next_seq('s_grpt'); $acc_operation = new Acc_Operation($this->db); $acc_operation->date = $e_date; $sposte = $fPoste->strAttribut(ATTR_DEF_ACCOUNT); // if 2 accounts if (strpos($sposte, ',') != 0) { $array = explode(',', $sposte); if (${"e_other{$i}" . "_amount"} < 0) { $poste_val = $array[1]; } else { $poste_val = $array[0]; } } else { $poste_val = $sposte; } $acc_operation->poste = $poste_val; $acc_operation->amount = ${"e_other{$i}" . "_amount"} * -1; $acc_operation->grpt = $seq; $acc_operation->jrn = $p_jrn; $acc_operation->type = 'd'; if (isset($periode)) { $tperiode = $periode; } else { $per = new Periode($this->db); $tperiode = $per->find_periode($e_date); } $acc_operation->periode = $tperiode; $acc_operation->qcode = ${"e_other" . $i}; $j_id = $acc_operation->insert_jrnx(); $acc_operation = new Acc_Operation($this->db); $acc_operation->date = $e_date; $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT); // if 2 accounts if (strpos($sposte, ',') != 0) { $array = explode(',', $sposte); if (${"e_other{$i}" . "_amount"} < 0) { $poste_val = $array[1]; } else { $poste_val = $array[0]; } } else { $poste_val = $sposte; } $acc_operation->poste = $poste_val; $acc_operation->amount = ${"e_other{$i}" . "_amount"}; $acc_operation->grpt = $seq; $acc_operation->jrn = $p_jrn; $acc_operation->type = 'd'; $acc_operation->periode = $tperiode; $acc_operation->qcode = $e_bank_account; $acc_operation->insert_jrnx(); if (sql_string(${"e_other{$i}" . "_comment"}) == null) { // if comment is blank set a default one $comment = " compte : " . $fBank->strAttribut(ATTR_DEF_NAME) . ' a ' . $fPoste->strAttribut(ATTR_DEF_NAME); } else { $comment = ${'e_other' . $i . '_comment'}; } $acc_operation = new Acc_Operation($this->db); $acc_operation->jrn = $p_jrn; $acc_operation->amount = abs(${"e_other{$i}" . "_amount"}); $acc_operation->date = $e_date; $acc_operation->desc = $comment; $acc_operation->grpt = $seq; $acc_operation->periode = $tperiode; $acc_operation->mt = $mt; $idx_operation++; $acc_operation->pj = ''; if (trim($e_pj) != '' && $this->numb_operation() == true) { $acc_operation->pj = $e_pj . str_pad($idx_operation, 3, 0, STR_PAD_LEFT); } if (trim($e_pj) != '' && $this->numb_operation() == false) { $acc_operation->pj = $e_pj; } $jr_id = $acc_operation->insert_jrn(); // $acc_operation->set_pj(); $this->db->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id)); $internal = $this->compute_internal_code($seq); if (trim(${"e_concerned" . $i}) != "") { if (strpos(${"e_concerned" . $i}, ',') != 0) { $aRapt = explode(',', ${"e_concerned" . $i}); foreach ($aRapt as $rRapt) { // Add a "concerned operation to bound these op.together // $rec = new Acc_Reconciliation($this->db); $rec->set_jr_id($jr_id); if (isNumber($rRapt) == 1) { $rec->insert($rRapt); } } } else { if (isNumber(${"e_concerned" . $i}) == 1) { $rec = new Acc_Reconciliation($this->db); $rec->set_jr_id($jr_id); $rec->insert(${"e_concerned{$i}"}); } } } // Set Internal code $this->grpt_id = $seq; /** * save also into quant_fin */ $this->insert_quant_fin($fBank->id, $jr_id, $fPoste->id, ${"e_other{$i}" . "_amount"}); if ($g_parameter->MY_ANALYTIC != "nu") { // for each item, insert into operation_analytique */ $op = new Anc_Operation($this->db); $op->oa_group = $this->db->get_next_seq("s_oa_group"); /* for analytic */ $op->j_id = $j_id; $op->oa_date = $e_date; $op->oa_debit = 'f'; $op->oa_description = sql_string($comment); $op->save_form_plan($_POST, $i, $j_id); } $this->update_internal_code($internal); $js_detail = HtmlInput::detail_op($jr_id, $internal); // Compute display $row = td($e_date) . td($js_detail) . td(${"e_other{$i}"}) . td($fPoste->strAttribut(ATTR_DEF_NAME)) . td(${"e_other" . $i . "_comment"}) . td(nbm(${"e_other{$i}" . "_amount"}), 'class="num"'); $class = $i % 2 == 0 ? ' class="even" ' : ' class="odd" '; $ret .= tr($row, $class); if ($i == 0) { // first record we upload the files and // keep variable to update other row of jrn if (isset($_FILES)) { $oid = $this->db->save_upload_document($seq); } } else { if ($oid != 0) { $this->db->exec_sql("update jrn set jr_pj=\$1 , jr_pj_name=\$2,\n jr_pj_type=\$3 where jr_grpt_id=\$4", array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq)); } } } // for nbitem // increment pj if (strlen(trim($e_pj)) != 0) { $this->inc_seq_pj(); } $ret .= '</table>'; } catch (Exception $e) { $r = '<span class="error">' . 'Erreur dans l\'enregistrement ' . __FILE__ . ':' . __LINE__ . ' ' . $e->getMessage(); $this->db->rollback(); throw new Exception($r); } $this->db->commit(); $r = ""; $r .= "<br>Ancien solde " . nbm($solde); $new_solde = bcadd($new_solde, $amount); $r .= "<br>Nouveau solde " . nbm($new_solde); $ret .= $r; return $ret; }