function build_tmp_table($p_array) { global $cn, $g_user; // exercice if (isset($p_array['state_exercice'])) { $periode = new Periode($cn); $date = format_date($p_array['state_exercice'], 'YYYY-MM-DD'); $periode->find_periode($date); } else { $periode_id = $g_user->get_periode(); $periode = new Periode($cn, $periode_id); } $periode->load(); $tmp_id = $cn->get_next_seq("public.tmp_stockgood_s_id_seq"); $cn->exec_sql("delete from tmp_stockgood where s_date < now() - interval '2 days' "); $cn->exec_sql("insert into tmp_stockgood(s_id) values (\$1)", array($tmp_id)); // get all readable repository $a_repository = $g_user->get_available_repository('R'); // From ACH : IN $sql_repo_detail = "\n\t\t\tinsert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)\n\t\t\t\tselect {$tmp_id},trim(sg_code), coalesce(sum(sg_quantity),0) as qin,r_id,f_id\n\t\t\t\tfrom stock_goods\n\t\t\t\twhere\n\t\t\t\t\tsg_type='d'\n\t\t\t\t\tand j_id is not null\n\t\t\t\t\tand j_id in (select j_id from jrnx where j_tech_per in (select p_id from parm_periode where p_exercice=\$2))\n\t\t\t\t\tand r_id in (select r_id from profile_sec_repository where p_id=\$1)\n\t\t\t\t\tgroup by r_id,trim(sg_code),f_id\n\t\t\t"; // From VEN : out $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice)); $sql_repo_detail = "\n\t\t\t\tinsert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)\n\t\t\t\tselect {$tmp_id},trim(sg_code) , coalesce(sum(sg_quantity),0) as qout,r_id,f_id\n\t\t\t\tfrom stock_goods as sg\n\t\t\t\twhere\n\t\t\t\t\tsg_type='c'\n\t\t\t\t\tand sg.j_id is not null\n\t\t\t\t\tand sg.j_id in (select j_id from jrnx where j_tech_per in (select p_id from parm_periode where p_exercice=\$2))\n\t\t\t\t\tand sg.r_id in (select r_id from profile_sec_repository where p_id=\$1)\n\t\t\t\t\tgroup by r_id,trim(sg_code),f_id\n\t\t\t"; $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice)); // From INV IN $sql_repo_detail = "\n\t\t\tinsert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)\n\t\t\t\tselect {$tmp_id},trim(sg_code) , coalesce(sum(sg_quantity),0) as qin,r_id,f_id\n\t\t\t\tfrom stock_goods as sg\n\t\t\t\twhere\n\t\t\t\t\tsg_type='d'\n\t\t\t\t\tand j_id is null\n\t\t\t\t\tand sg_date >= ( select min(p_start) from parm_periode where p_exercice=\$2)\n\t\t\t\t\tand sg_date <= ( select max(p_end) from parm_periode where p_exercice=\$2)\n\t\t\t\t\t and sg.r_id in (select r_id from profile_sec_repository where p_id=\$1)\n\t\t\t\t\tgroup by r_id,trim(sg_code),f_id\n\t\t\t"; // From INV: OUT $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice)); $sql_repo_detail = "\n\t\t\t\tinsert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)\n\t\t\t\tselect {$tmp_id},trim(sg_code), coalesce(sum(sg_quantity),0) as qout,r_id,f_id\n\t\t\t\tfrom stock_goods\n\t\t\t\twhere\n\t\t\t\t\tsg_type='c'\n\t\t\t\t\tand j_id is null\n\t\t\t\t\t and r_id in (select r_id from profile_sec_repository where p_id=\$1)\n and sg_date >= ( select min(p_start) from parm_periode where p_exercice=\$2)\n\t\t\t\t\tand sg_date <= ( select max(p_end) from parm_periode where p_exercice=\$2)\t\t\t\t\t\n group by r_id,trim(sg_code),f_id\n\t\t\t"; $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice)); return $tmp_id; }
/** * @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; }
static function parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval = true, $p_type_date = 0, $p_sql = "") { global $g_user; if (Impress::check_formula($p_formula) == false) { if ($p_eval == true) { return array('desc' => $p_label . ' Erreur Formule!', 'montant' => 0); } else { return $p_formula; } } if ($p_type_date == 0) { $cond = sql_filter_per($p_cn, $p_start, $p_end, 'p_id', 'j_tech_per'); } else { $cond = "( j_date >= to_date('{$p_start}','DD.MM.YYYY') and j_date <= to_date('{$p_end}','DD.MM.YYYY'))"; } include_once "class_acc_account_ledger.php"; while (preg_match_all("(\\[[0-9]*[A-Z]*%*c*d*s*\\])", $p_formula, $e) == true) { // remove the [ ] $x = $e[0]; foreach ($x as $line) { $compute = 'all'; if (strpos($line, 'd') != 0) { $compute = 'deb'; } if (strpos($line, 'c') != 0) { $compute = 'cred'; } if (strpos($line, 's') != 0) { $compute = 'signed'; } $line = str_replace("[", "", $line); $line = str_replace("]", "", $line); $line = str_replace("d", "", $line); $line = str_replace("c", "", $line); $line = str_replace("s", "", $line); // If there is a FROM clause we must recompute // the time cond if ($p_type_date == 0 && preg_match("/FROM=[0-9]+\\.[0-9]+/", $p_formula, $afrom) == 1) { // There is a FROM clause // then we must modify the cond for the periode $from = str_replace("FROM=", "", $afrom[0]); // Get the periode /*! \note special value for the clause FROM=00.0000 */ if ($from == '00.0000') { // retrieve the first month of this periode $user_periode = $g_user->get_periode(); $oPeriode = new Periode($p_cn); $periode = $oPeriode->get_exercice($user_periode); list($first, $last) = $oPeriode->get_limit($periode); $ret = $first->get_date_limit(); $end_date = $oPeriode->get_date_limit($p_end); if ($ret == null) { throw new Exception('Pas de limite à cette période', 1); } $cond = sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per'); } else { $oPeriode = new Periode($p_cn); try { $pfrom = $oPeriode->find_periode('01.' . $from); $cond = sql_filter_per($p_cn, $pfrom, $p_end, 'p_id', 'j_tech_per'); } catch (Exception $exp) { /* if none periode is found then we take the first periode of the year */ $user_periode = $g_user->get_periode(); $year = $oPeriode->get_exercice($user_periode); list($first, $last) = $oPeriode->get_limit($year); $ret = $first->get_date_limit(); $end_date = $oPeriode->get_date_limit($p_end); if ($ret == null) { throw new Exception('Pas de limite à cette période', 1); } $cond = sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per'); } } } if (strpos($p_formula, "FROM") != 0) { // We remove FROM out of the p_formula $p_formula = substr_replace($p_formula, "", strpos($p_formula, "FROM")); } // Get sum of account $P = new Acc_Account_Ledger($p_cn, $line); $detail = $P->get_solde_detail($cond . $p_sql); if ($compute == 'all') { $i = $detail['solde']; } if ($compute == 'deb') { $i = $detail['debit']; } if ($compute == 'cred') { $i = $detail['credit']; } if ($compute == 'signed') { $i = $detail['debit'] - $detail['credit']; } $p_formula = str_replace($x[0], $i, $p_formula); } } // $p_eval is true then we eval and returns result if ($p_eval == true) { $p_formula = "\$result=" . $p_formula . ";"; eval("{$p_formula}"); while (preg_match("/\\[([0-9]+)([Tt]*)\\]/", trim($p_label), $e) == 1) { $nom = "!!" . $e[1] . "!!"; if (Impress::check_formula($e[0])) { $nom = $p_cn->get_value("SELECT pcm_lib AS acct_name FROM tmp_pcmn WHERE pcm_val::text LIKE \$1||'%' ORDER BY pcm_val ASC LIMIT 1", array($e[1])); if ($nom) { if ($e[2] == 'T') { $nom = strtoupper($nom); } if ($e[2] == 't') { $nom = strtolower($nom); } } } $p_label = str_replace($e[0], $nom, $p_label); } $aret = array('desc' => $p_label, 'montant' => $result); return $aret; } else { // $p_eval is false we returns only the string return $p_formula; } }
function record_save($p_array) { global $cn; try { if (isDate($p_array['p_date']) == null) { throw new Exception('Date invalide'); } $cn->start(); $ch = new Stock_Change_Sql($cn); $ch->setp("c_comment", $p_array['p_motif']); $ch->setp("r_id", $p_array['p_depot']); $ch->setp("c_date", $p_array['p_date']); $ch->setp('tech_user', $_SESSION['g_user']); $ch->insert(); $per = new Periode($cn); $periode = $per->find_periode($p_array['p_date']); $exercice = $per->get_exercice($periode); $nb = $p_array['row']; for ($i = 0; $i < $nb; $i++) { $a = new Stock_Goods_Sql($cn); if ($p_array['sg_quantity' . $i] != 0 && trim($p_array['sg_code' . $i]) != '') { $stock = strtoupper(trim($p_array['sg_code' . $i])); $fiche = new Fiche($cn); $fiche->get_by_qcode($p_array['sg_code' . $i]); /* * check if code stock does exist */ $count = $cn->get_value('select count(*) from fiche_detail where ad_id=$1 and ad_value=$2', array(ATTR_DEF_STOCK, $stock)); if ($count == 0) { throw new Exception("Code stock inexistant"); } $a->f_id = $fiche->id; $a->sg_code = $stock; $a->sg_quantity = abs($p_array['sg_quantity' . $i]); $a->sg_type = $p_array['sg_quantity' . $i] > 0 ? 'd' : 'c'; $a->sg_comment = $p_array['p_motif']; $a->tech_user = $_SESSION['g_user']; $a->r_id = $p_array['p_depot']; $a->sg_exercice = $exercice; $a->c_id = $ch->c_id; $a->sg_date = $p_array['p_date']; $a->insert(); } } $cn->commit(); } catch (Exception $exc) { echo $exc->getTraceAsString(); throw $exc; } }
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; }
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; }