diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 173edfb35..63b197768 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -338,7 +338,12 @@ $path = array( "operation_exercice+display_total"=>"ajax_operation_exercice", // delete row in exercice (opening/closing) operation "operation_exercice+delete_row"=>"ajax_operation_exercice", - + // date in exercice (opening/closing) operation + "operation_exercice+date"=>"ajax_operation_exercice", + // text in exercice (opening/closing) operation + "operation_exercice+text"=>"ajax_operation_exercice", + // transfer operation to accountancy + 'operation_exercice+transfer'=>"ajax_operation_exercice", ) ; if (array_key_exists($op, $path)) { diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index 8c205ff85..5952e76b9 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -1697,7 +1697,7 @@ var operation_exercice = { console.error('oe-update_periode', e.message); } }, - modify_row: function (row_operation_exercice,oe_id) { + modify_row: function (row_operation_exercice, oe_id) { try { var dgbox = "operation_exercice_bx"; waiting_box(); @@ -1708,7 +1708,7 @@ var operation_exercice = { console.debug(row_operation_exercice); var queryString = { op: 'operation_exercice+modify_row', - oe_id : oe_id, + oe_id: oe_id, row_id: row_operation_exercice, gDossier: $('gDossier').value }; @@ -1764,18 +1764,20 @@ var operation_exercice = { } if (req.responseJSON['status'] == "OK") { - rowid=req.responseJSON['row_id']; + rowid = req.responseJSON['row_id']; if (queryString['row_id'] == -1) { var row = new Element("tr"); - row.id="oe_"+rowid; - row.setAttribute("oed_id",rowid); - row.setAttribute("oe_id",req.responseJSON['oe_id']); + row.id = "oe_" + rowid; + row.setAttribute("oed_id", rowid); + row.setAttribute("oe_id", req.responseJSON['oe_id']); row.update(req.responseJSON['content']); $("operation_exercice_tb").appendChild(row); - row.addEventListener("click",function(event) {operation_exercice.click_modify_row(row)}) + row.addEventListener("click", function (event) { + operation_exercice.click_modify_row(row) + }) - } else{ - $("oe_"+rowid).update(req.responseJSON['content']); + } else { + $("oe_" + rowid).update(req.responseJSON['content']); } new Effect.Highlight("oe_" + req.responseJSON['row_id'], { startcolor: '#FAD4D4', @@ -1863,6 +1865,39 @@ var operation_exercice = { } }, click_modify_row: function (item) { - operation_exercice.modify_row(item.getAttribute("oed_id"),item.getAttribute("oe_id")); + operation_exercice.modify_row(item.getAttribute("oed_id"), item.getAttribute("oe_id")); + }, + /** + * check and transfer if it is good + */ + transfer: function () { + try { + var dgbox = "oe_transfer_div"; + waiting_box(); + + var queryString = $("operation_exercice_transfer_frm").serialize(true); + var action = new Ajax.Request( + "ajax_misc.php", + { + method: 'GET', + parameters: queryString, + onFailure: ajax_misc_failure, + onSuccess: function (req) { + remove_waiting_box(); + if (req.responseText == 'NOCONX') { + reconnect(); + return; + } + var answer=req.responseJSON; +console.debug(answer['content']); + $('operation_exercice_transfer_info').update(answer.content); + + + } + } + ); + } catch (e) { + alert_box(e.message); + } } } diff --git a/include/ajax/ajax_operation_exercice.php b/include/ajax/ajax_operation_exercice.php index 0b253ac3d..af43693b6 100644 --- a/include/ajax/ajax_operation_exercice.php +++ b/include/ajax/ajax_operation_exercice.php @@ -52,14 +52,14 @@ if ($op == "operation_exercice+update_periode") { if ($op == "operation_exercice+modify_row") { try { $row_id = $http->post("row_id", "number", -1); - $oe_id=$http->post("oe_id","number"); + $oe_id = $http->post("oe_id", "number"); } catch (\Exception $e) { echo $e->getMessage(); return; } $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id); - $operation_detail_sql->oe_id=$oe_id; - if ( $row_id == -1) $operation_detail_sql->oed_debit='f'; + $operation_detail_sql->oe_id = $oe_id; + if ($row_id == -1) $operation_detail_sql->oed_debit = 'f'; Operation_Exercice::input_row($operation_detail_sql); return; @@ -86,7 +86,7 @@ if ($op == "operation_exercice+save_row") { ->setp("oed_qcode", $qcode) ->setp("oed_label", $label) ->setp("oed_amount", $amount) - ->setp("oe_id",$oe_id) + ->setp("oe_id", $oe_id) ->setp("oed_debit", $debit); try { $operation_detail_sql->save(); @@ -94,7 +94,7 @@ if ($op == "operation_exercice+save_row") { ob_start(); $operation_exercice = new Operation_Exercice(); - if ($row_id == -1 ) { + if ($row_id == -1) { $operation_exercice->display_row($data, true); } else { @@ -140,14 +140,108 @@ if ($op == "operation_exercice+delete_row") { try { $row_id = $http->get("row_id", "number"); $operation_detail_sql = new Operation_Exercice_Detail_SQL($cn, $row_id); - $oe_id=$operation_detail_sql->oe_id; - $other_row=$cn->get_value("select oed_id from operation_exercice_detail where oe_id=$1 limit 1 ", - [$oe_id]); + $oe_id = $operation_detail_sql->oe_id; + $other_row = $cn->get_value("select oed_id from operation_exercice_detail where oe_id=$1 limit 1 ", + [$oe_id]); $operation_detail_sql->delete(); - echo json_response(array("status"=>"OK","row_id"=>$other_row)); + echo json_response(array("status" => "OK", "row_id" => $other_row)); } catch (\Exception $e) { echo $e->getMessage(); return; } } +//------------------------------------------------------------------------------------------- +// Change the date +//------------------------------------------------------------------------------------------- +if ($op == "operation_exercice+date") { + try { + $oe_id = $http->request("oe_id", "number"); + } catch (\Exception $e) { + echo $e->getMessage(); + } + $input = $http->request("input"); + $action = $http->request("ieaction", "string", "display"); + $ajax_date = Inplace_Edit::build($input); + $ajax_date->add_json_param("op", "operation_exercice+date"); + $ajax_date->add_json_param("gDossier", Dossier::id()); + $ajax_date->add_json_param("oe_id", $oe_id); + $ajax_date->set_callback("ajax_misc.php"); + + if ($action == "display") { + + echo $ajax_date->ajax_input(); + } + if ($action == "ok") { + $value = $http->request("value"); + $cn->exec_sql("update operation_exercice set oe_date=to_date($1,'DD.MM.YYYY') where oe_id=$2", [$value, $oe_id]); + $ajax_date->set_value($value); + echo $ajax_date->value(); + } + if ($action == "cancel") { + + echo $ajax_date->value(); + } + return; +} +//------------------------------------------------------------------------------------------- +// Change the text +//------------------------------------------------------------------------------------------- +if ($op == "operation_exercice+text") { + try { + $oe_id = $http->request("oe_id", "number"); + } catch (\Exception $e) { + echo $e->getMessage(); + } + $input = $http->request("input"); + $action = $http->request("ieaction", "string", "display"); + $ajax_text = Inplace_Edit::build($input); + $ajax_text->add_json_param("op", "operation_exercice+text"); + $ajax_text->add_json_param("gDossier", Dossier::id()); + $ajax_text->add_json_param("oe_id", $oe_id); + $ajax_text->set_callback("ajax_misc.php"); + + if ($action == "display") { + + echo $ajax_text->ajax_input(); + } + if ($action == "ok") { + $value = $http->request("value"); + $cn->exec_sql("update operation_exercice set oe_text=$1 where oe_id=$2", [$value, $oe_id]); + $ajax_text->set_value($value); + echo $ajax_text->value(); + } + if ($action == "cancel") { + + echo $ajax_text->value(); + } + return; +} +//------------------------------------------------------------------------------------------- +// Check and transfer to accountancy if OK +//------------------------------------------------------------------------------------------- +if ($op == "operation_exercice+transfer") { + try { + $operation_exercice_id = $http->request("oe_id", "number"); + $ledger_id = $http->request('p_jrn', "number"); + if ($g_user->check_jrn($ledger_id) == "X") throw new \Exception (EXC_FORBIDDEN); + } catch (\Exception $e) { + echo $e->getMessage(); + return; + } + // first , check that everything is ok + $operation_exercice = new Operation_Exercice($operation_exercice_id); + + global $oe_result, $oe_status; + $answer = array(); + $operation_exercice->submit_transfer($ledger_id); + $answer['status'] = $oe_status; + if ($answer['status'] == 'NOK') { + $answer['content'] = span($oe_result, 'class=warning'); + }else { + $answer['content'] = span($oe_result); + + } + echo json_response($answer); + return; +} \ No newline at end of file diff --git a/include/class/operation_closing.class.php b/include/class/operation_closing.class.php index b82a6bc1d..2794e22d3 100644 --- a/include/class/operation_closing.class.php +++ b/include/class/operation_closing.class.php @@ -24,13 +24,26 @@ class Operation_Closing extends Operation_Exercice { private $signature ; + private $exercice; - function __construct() + function __construct($p_id) { - parent::__construct(); + parent::__construct($p_id); $this->signature='closing'; } + public function get_exercice() + { + return $this->exercice; + } + + /** + * @param mixed $exercice + */ + public function set_exercice($exercice): void + { + $this->exercice = $exercice; + } public function get_signature(): string { return $this->signature; @@ -38,6 +51,76 @@ class Operation_Closing extends Operation_Exercice function from_request() { + $http = new HttpInput(); + $this->exercice = $http->request("exercice_cl", "number"); + } + /** + * @brief insert data into data operation_exercice and operation_exercice_detail + * @return void + */ + function insert() + { + $cn = Dossier::connect(); + + $sql = " +with total_account as ( + select sum(a.montant) as tot_amount, j_poste, f_id + from + (select j_id, case when j_debit='t' then j_montant + else j_montant * (-1) end as montant + from jrnx) as a + join jrnx using (j_id) + join parm_periode on (j_tech_per = p_id ) + where + p_exercice=$1 + and( j_poste::text like '7%' + or j_poste::text like '6%') + group by j_poste,f_id + having (sum(a.montant) != 0 ) + ) +select t1.tot_amount + ,t1.j_poste + ,(select pcm_lib from tmp_pcmn where pcm_val=t1.j_poste) as lib_accounting + ,t1.f_id + ,(select ad_value fd2 from fiche_detail fd2 where fd2.f_id=t1.f_id and fd2.ad_id=23) qcode +,(select fd3.ad_value from fiche_detail fd3 where fd3.f_id=t1.f_id and fd3.ad_id=1) f_name +,abs(t1.tot_amount) atot_amount +,case when tot_amount <0 then 'f' else 't' end debit +from total_account t1 +"; + $exercice_report=$this->exercice; + $this->operation_exercice_sql->setp("oe_type", $this->signature) + ->setp("oe_dossier_id", Dossier::id()) + ->set("oe_text",_("Ecriture cloture $exercice_report")) + ->setp("oe_exercice", $this->exercice); + try { + $cn->start(); + $this->operation_exercice_sql->insert(); + $array = $cn->get_array($sql, array($this->exercice)); + if (empty($array)) return; + foreach ($array as $item) { + $row = new Operation_Exercice_Detail_SQL($cn); + $row->oe_id = $this->operation_exercice_sql->oe_id; + $row->oed_poste = (empty($item['qcode']))?$item["j_poste"]:null; + $row->oed_qcode = $item["qcode"]; + $row->oed_amount = $item['atot_amount']; + $row->oed_label=(empty($item['qcode']))?$item['lib_accounting']:$item['f_name']; + $row->oed_debit = $item["debit"]; + $row->save(); + } + $cn->commit(); + + } catch (\Exception $e) { + $cn->rollback(); + echo $e->getMessage(); + throw $e; + } } + public function display_result() + { + echo h2("Clôture compte"); + + parent::display_result(); // TODO: Change the autogenerated stub + } } \ No newline at end of file diff --git a/include/class/operation_exercice.class.php b/include/class/operation_exercice.class.php index 076463357..d76e4bd05 100644 --- a/include/class/operation_exercice.class.php +++ b/include/class/operation_exercice.class.php @@ -26,6 +26,7 @@ class Operation_Exercice { protected $operation_exercice_sql; + public function __construct($p_id = -1) { $this->operation_exercice_sql = new Operation_Exercice_SQL(Dossier::connect(), $p_id); @@ -42,6 +43,27 @@ class Operation_Exercice function display_result() { + $date = new IDate("exercice_date"); + $date->id = "exercice_date"; + $date->value = format_date($this->operation_exercice_sql->getp("oe_date"), "DD.MM.YYYY"); + $inplace_date = new Inplace_Edit($date); + $inplace_date->add_json_param("op", "operation_exercice+date"); + $inplace_date->add_json_param("gDossier", Dossier::id()); + $inplace_date->add_json_param("oe_id", $this->operation_exercice_sql->oe_id); + $inplace_date->set_callback("ajax_misc.php"); + echo _("Date"), $inplace_date->input(); + + $text_operation = new IText("text_operation"); + $text_operation->id = uniqid("text"); + $text_operation->size = 80; + $text_operation->value = $this->operation_exercice_sql->getp("oe_text"); + $inplace_text = new Inplace_Edit($text_operation); + $inplace_text->add_json_param("op", "operation_exercice+text"); + $inplace_text->add_json_param("gDossier", Dossier::id()); + $inplace_text->add_json_param("oe_id", $this->operation_exercice_sql->oe_id); + $inplace_text->set_callback("ajax_misc.php"); + echo $inplace_text->input(); + $cn = Dossier::connect(); // get data $a_data = $cn->get_array(" @@ -59,6 +81,7 @@ class Operation_Exercice ", [$this->operation_exercice_sql->oe_id]); $aheader = array(_("Poste"), _("Fiche"), _("Libellé"), _("Montant"), _("Débit/Crédit")); + echo '
'; echo \HtmlInput::filter_table("operation_exercice_tb", '0,1,2,3,4', 1); echo \HtmlInput::button_action(_("Ajouter une ligne"), sprintf("operation_exercice.modify_row('-1','%s')", $this->operation_exercice_sql->oe_id)); echo '