<?php /** //This file is part of NOALYSS and is under GPL //see licence.txt */ /** * @brief show the common parts of operation details * * Variables : $div = popup or box (det[0-9] * */ // Contains all the linked actions $a_followup = Follow_Up::get_all_operation($jr_id); // // Contains all the linked operations $oRap = new Acc_Reconciliation($cn); $oRap->jr_id = $jr_id; $aRap = $oRap->get(); // Detail of operation $detail = new Acc_Misc($cn, $obj->jr_id); $detail->get(); $nb_document = $detail->det->jr_pj_name != "" ? 1 : 0; // Array of tab // $a_tab['writing_div'] = array('id' => 'writing_div' . $div, 'label' => _('Ecriture Comptable'), 'display' => 'none'); $a_tab['info_operation_div'] = array('id' => 'info_operation_div' . $div, 'label' => _('Information'), 'display' => 'none'); $a_tab['linked_operation_div'] = array('id' => 'linked_operation_div' . $div, 'label' => _('Opérations liées') . '(' . count($aRap) . ')', 'display' => 'none'); $a_tab['document_operation_div'] = array('id' => 'document_operation_div' . $div, 'label' => _('Document') . '(' . $nb_document . ')', 'display' => 'block'); $a_tab['linked_action_div'] = array('id' => 'linked_action_div' . $div, 'label' => _('Actions Gestion') . '(' . count($a_followup) . ')', 'display' => 'none'); $a_tab['analytic_div'] = array('id' => 'analytic_div' . $div, 'label' => _('Comptabilité Analytique'), 'display' => 'none'); // show tabs
static function test_me() { $cn = new Database(dossier::id()); $rap = new Acc_Reconciliation($cn); var_dump($rap->get_reconciled_amount('', false)); }
<td></td> <?php } else { ?> <td></td> <td style="text-align:right"> <?php echo nb($this->content[$i]['j_montant']); ?> </td> <?php } ?> <td style="text-align:center"> <?php // Rapprochement $rec = new Acc_Reconciliation($this->db); $rec->set_jr_id($this->content[$i]['jr_id']); $a = $rec->get(); if ($a != null) { foreach ($a as $key => $element) { $operation = new Acc_Operation($this->db); $operation->jr_id = $element; $l_amount = $this->db->get_value("select jr_montant from jrn " . " where jr_id={$element}"); echo "<A class=\"detail\" HREF=\"javascript:viewOperation('" . $element . "'," . $gDossier . ")\" > " . $operation->get_internal() . " [ {$l_amount} € ]</A>"; } //for } // if ( $a != null ) { ?> </td>
* variable set $g_user,$cn * @see impress_rec.inc.php */ if (!defined('ALLOWED')) { die('Appel direct ne sont pas permis'); } $Date = date('Ymd'); $filename = "reconcialed_operation-" . $Date; header('Pragma: public'); header('Content-type: application/csv'); header('Content-Disposition: attachment;filename="' . $filename . '.csv"', FALSE); require_once NOALYSS_INCLUDE . '/class_acc_reconciliation.php'; require_once NOALYSS_INCLUDE . '/ac_common.php'; require_once NOALYSS_INCLUDE . '/class_database.php'; require_once NOALYSS_INCLUDE . '/class_dossier.php'; // -------------------------- // Check if all mandatory arg are passed foreach (array('choice', 'p_end', 'p_start') as $arg) { if (!isset($_GET[$arg])) { die("argument [" . $arg . "] is missing"); } } extract($_GET); $r_jrn = isset($r_jrn) ? $r_jrn : ''; // ------------------------- // Create object and export $acc_reconciliation = new Acc_Reconciliation($cn); $acc_reconciliation->a_jrn = $r_jrn; $acc_reconciliation->start_day = $p_start; $acc_reconciliation->end_day = $p_end; $array = $acc_reconciliation->export_csv($choice);
$radio->value = 2; echo '<li>' . $radio->input() . _('Opérations rapprochées avec des montants identiques') . '</li>'; $radio->selected = $choice == 3 ? true : false; $radio->value = 3; echo '<li>' . $radio->input() . _('Opérations non rapprochées') . '</li>'; echo '</ol>'; echo HtmlInput::submit('vis', _('Visualisation')); echo '</form>'; echo '<hr>'; echo '</div>'; echo '</div>'; echo '<div class="content">'; if (!isset($_GET['vis'])) { return; } $acc_reconciliation = new Acc_Reconciliation($cn); $acc_reconciliation->a_jrn = $r_jrn; $acc_reconciliation->start_day = $dstart->value; $acc_reconciliation->end_day = $dend->value; $array = $acc_reconciliation->get_data($choice); $gDossier = Dossier::id(); ?> <form method="get" action="export.php"> <?php echo HtmlInput::get_to_hidden(array('ac', 'gDossier', 'p_end', 'p_start', 'choice', 'r_jrn')); echo HtmlInput::hidden('act', 'CSV:Reconciliation'); echo HtmlInput::submit("csv_bt", "Export CSV"); ?> </form> <?php require_once NOALYSS_INCLUDE . '/template/impress_reconciliation.php';
/** * @brief Show the form to encode your operation * @param$p_array if you correct or use a predef operation (default = null) * @param$p_readonly 1 for readonly 0 for writable (default 0) *@exception if ledger not found * \return a string containing the form */ function input($p_array = null, $p_readonly = 0) { global $g_parameter, $g_user; $this->nb = $this->get_min_row(); if ($p_readonly == 1) { return $this->confirm($p_array); } if ($p_array != null) { extract($p_array); } $add_js = ""; if ($g_parameter->MY_PJ_SUGGEST == 'Y') { $add_js = "update_pj();"; } if ($g_parameter->MY_DATE_SUGGEST == 'Y') { $add_js .= 'get_last_date();'; } $add_js .= 'update_row("quick_item");'; $ret = ""; if ($g_user->check_action(FICADD) == 1) { /* Add button */ $f_add_button = new IButton('add_card'); $f_add_button->label = _('Créer une nouvelle fiche'); $f_add_button->set_attribute('ipopup', 'ipop_newcard'); $f_add_button->set_attribute('jrn', $this->id); $f_add_button->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);"; $f_add_button->input(); } $wLedger = $this->select_ledger('ODS', 2); if ($wLedger == null) { throw new Exception(_('Pas de journal disponible')); } $wLedger->javascript = "onChange='update_name();update_predef(\"ods\",\"t\",\"" . $_REQUEST['ac'] . "\");{$add_js}'"; $label = " Journal " . HtmlInput::infobulle(2); $ret .= $label . $wLedger->input(); // Load the javascript // $ret .= "<table>"; $ret .= '<tr ><td colspan="2" style="width:auto">'; $wDate = new IDate('e_date'); $wDate->readonly = $p_readonly; $e_date = isset($e_date) && trim($e_date) != '' ? $e_date : ''; $wDate->value = $e_date; $ret .= _("Date") . ' : ' . $wDate->input(); $ret .= '</td>'; /* insert periode if needed */ // Periode //-- if ($this->check_periode() == true) { $l_user_per = $g_user->get_periode(); $def = isset($periode) ? $periode : $l_user_per; $period = new IPeriod("period"); $period->user = $g_user; $period->cn = $this->db; $period->value = $def; $period->type = OPEN; try { $l_form_per = $period->input(); } catch (Exception $e) { if ($e->getCode() == 1) { echo _("Aucune période ouverte"); exit; } } $label = HtmlInput::infobulle(3); $f_periode = _("Période comptable") . " {$label} " . $l_form_per; $ret .= td($f_periode); } $wPJ = new IText('e_pj'); $wPJ->readonly = false; $wPJ->size = 10; /* suggest PJ ? */ $default_pj = ''; if ($g_parameter->MY_PJ_SUGGEST == 'Y') { $default_pj = $this->guess_pj(); } $wPJ->value = isset($e_pj) ? $e_pj : $default_pj; $ret .= '</tr>'; $ret .= '<tr >'; $ret .= '<td colspan="2" style="width:auto"> ' . _('Pièce') . ' : ' . $wPJ->input(); $ret .= HtmlInput::hidden('e_pj_suggest', $default_pj); $ret .= '</tr>'; $ret .= '</td>'; $ret .= '<tr>'; $ret .= '<td colspan="2" style="width:auto">'; $ret .= _('Libellé'); $wDescription = new IText('desc'); $wDescription->readonly = $p_readonly; $wDescription->size = "50"; $wDescription->value = isset($desc) ? $desc : ''; $ret .= $wDescription->input(); $ret .= '</td>'; $ret .= '</tr>'; $ret .= '</table>'; $nb_row = isset($nb_item) ? $nb_item : $this->nb; $ret .= HtmlInput::hidden('nb_item', $nb_row); $ret .= dossier::hidden(); $ret .= dossier::hidden(); $ret .= HtmlInput::hidden('jrn_type', $this->get_type()); $info = HtmlInput::infobulle(0); $info_poste = HtmlInput::infobulle(9); if ($g_user->check_action(FICADD) == 1) { $ret .= $f_add_button->input(); } $ret .= '<table id="quick_item" style="position:float;width:100%">'; $ret .= '<tr>' . '<th style="text-align:left">Quickcode' . $info . '</th>' . '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' . '<th style="text-align:left">' . _('Libellé') . '</th>' . '<th style="text-align:left">' . _('Montant') . '</th>' . '<th style="text-align:left">' . _('Débit') . '</th>' . '</tr>'; for ($i = 0; $i < $nb_row; $i++) { // Quick Code $quick_code = new ICard('qc_' . $i); $quick_code->set_dblclick("fill_ipopcard(this);"); $quick_code->set_attribute('ipopup', 'ipopcard'); // name of the field to update with the name of the card $quick_code->set_attribute('label', "ld" . $i); // name of the field to update with the name of the card $quick_code->set_attribute('typecard', 'filter'); // Add the callback function to filter the card on the jrn $quick_code->set_callback('filter_card'); $quick_code->set_function('fill_data'); $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name); $quick_code->value = isset(${'qc_' . $i}) ? ${'qc_' . $i} : ""; $quick_code->readonly = $p_readonly; $label = ''; if ($quick_code->value != '') { $Fiche = new Fiche($this->db); $Fiche->get_by_qcode($quick_code->value); $label = $Fiche->strAttribut(ATTR_DEF_NAME); } // Account $poste = new IPoste(); $poste->name = 'poste' . $i; $poste->set_attribute('jrn', $this->id); $poste->set_attribute('ipopup', 'ipop_account'); $poste->set_attribute('label', 'ld' . $i); $poste->set_attribute('account', 'poste' . $i); $poste->set_attribute('dossier', Dossier::id()); $poste->value = isset(${'poste' . $i}) ? ${"poste" . $i} : ''; $poste->dbl_click_history(); $poste->readonly = $p_readonly; if ($poste->value != '') { $Poste = new Acc_Account($this->db); $Poste->set_parameter('value', $poste->value); $label = $Poste->get_lib(); } // Description of the line $line_desc = new IText(); $line_desc->name = 'ld' . $i; $line_desc->size = 30; $line_desc->value = isset(${"ld" . $i}) ? ${"ld" . $i} : $label; // Amount $amount = new INum(); $amount->size = 10; $amount->name = 'amount' . $i; $amount->value = isset(${'amount' . $i}) ? ${"amount" . $i} : ''; $amount->readonly = $p_readonly; $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"'; // D/C $deb = new ICheckBox(); $deb->name = 'ck' . $i; $deb->selected = isset(${'ck' . $i}) ? true : false; $deb->readonly = $p_readonly; $deb->javascript = ' onChange="checkTotalDirect()"'; $ret .= '<tr>'; $ret .= '<td>' . $quick_code->input() . $quick_code->search() . '</td>'; $ret .= '<td>' . $poste->input() . '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' . '</td>'; $ret .= '<td>' . $line_desc->input() . '</td>'; $ret .= '<td>' . $amount->input() . '</td>'; $ret .= '<td>' . $deb->input() . '</td>'; $ret .= '</tr>'; // If readonly == 1 then show CA } $ret .= '</table>'; if (isset($this->with_concerned) && $this->with_concerned == true) { $oRapt = new Acc_Reconciliation($this->db); $w = $oRapt->widget(); $w->name = 'jrn_concerned'; $w->value = isset($jrn_concerned) ? $jrn_concerned : ""; $ret .= "Réconciliation/rapprochements : " . $w->input(); } $ret .= create_script("\$('" . $wDate->id . "').focus()"); return $ret; }
echo $e->getMessage(); } alert(_("Changement impossible: on ne peut pas changer la date dans une période fermée")); } $html = ob_get_contents(); ob_end_clean(); break; //////////////////////////////////////////////////////////////////////////// // remove a reconciliation //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // remove a reconciliation //////////////////////////////////////////////////////////////////////////// case 'rmr': if ($access == 'W') { $rec = new Acc_Reconciliation($cn); $rec->set_jr_id($jr_id); $rec->remove($_GET['jr_id2']); } break; //////////////////////////////////////////////////////////////////////////// // ask for a date for reversing the operation //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// // ask for a date for reversing the operation //////////////////////////////////////////////////////////////////////////// case 'ask_extdate': $date = new IDate('p_date'); $html .= "<form id=\"form_" . $div . "\" onsubmit=\"return reverseOperation(this);\">"; $html .= HtmlInput::hidden('jr_id', $_REQUEST['jr_id']) . HtmlInput::hidden('div', $div) . dossier::hidden() . HtmlInput::hidden('act', 'reverseop'); $html .= '<h2 class="info">' . _('entrez une date') . ' </H2>' . $date->input();
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; }
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; }