26 require_once NOALYSS_INCLUDE.
'/class/class_acc_ledger_purchase.php';
27 require_once NOALYSS_INCLUDE.
'/class/class_acc_ledger_sold.php';
28 require_once(
'class_modop_operation.php');
32 if ( $_POST[
'jrn_type'] ==
'ACH')
34 $jrn=
new Acc_Ledger_Purchase(
$cn,$_POST[
'p_jrn']);
38 $op->suspend_receipt();
39 $op->suspend_strict();
42 $cn->exec_sql(
'update jrn set jr_pj_number=$1 where jr_id=$2',
43 array($oldpj,$_POST[
'ext_jr_id']));
44 $new_internal=$jrn->insert($_POST);
48 alert($e->getMessage());
56 $cn->exec_sql(
'delete from stock_goods where j_id in (select j_id from jrnx join jrn on (j_grpt=jr_grpt_id) where jr_id=$1)',
57 array($_POST[
'ext_jr_id']));
60 $cn->exec_sql(
'delete from jrnx where j_grpt in (select jr_grpt_id from jrn where jr_id=$1)',
61 array($_POST[
'ext_jr_id']));
64 $attach=
$cn->get_array(
'select jr_pj,jr_pj_name,jr_pj_type from jrn where jr_id=$1',
65 array($_POST[
'ext_jr_id']));
69 $cn->exec_sql(
'delete from jrn where jr_id=$1',array($_POST[
'ext_jr_id']));
71 $cn->exec_sql(
'update jrn set jr_id=$1,jr_internal=$2,jr_pj_number=$3 where jr_internal=$4',
72 array($_POST[
'ext_jr_id'],$_POST[
'ext_jr_internal'],$pj,$new_internal));
73 if ( $attach[0][
'jr_pj_name'] !=
'' && ! isset ($_POST[
'gen_invoice']))
75 $cn->exec_sql(
'update jrn set jr_pj=$1,jr_pj_type=$2,jr_pj_name=$3 where jr_id=$4',
76 array($attach[0][
'jr_pj'],$attach[0][
'jr_pj_type'],$attach[0][
'jr_pj_name'],$_POST[
'ext_jr_id']));
79 $cn->exec_sql(
'update quant_purchase set qp_internal=$1 where qp_internal=$2',
80 array($_POST[
'ext_jr_internal'],$new_internal));
83 echo
'<h2 class="info"> '._(
'Enregistrement').
' </h2>';
84 echo
"<h2 >" . _(
'Opération sauvée') .$_POST[
'ext_jr_internal'] ;
86 echo
' Piece : ' . h($jrn->pj);
88 if (strcmp($jrn->pj, $_POST[
'e_pj']) != 0)
90 echo
'<h3 class="notice"> ' . _(
'Attention numéro pièce existante, elle a du être adaptée') .
'</h3>';
93 $obj =
new Acc_Ledger_Info(
$cn);
94 $obj->save_extra($jrn->jr_id, $_POST);
95 printf(
'<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a><hr>', $_POST[
'ext_jr_id'],
dossier::id(), $new_internal);
97 $jrn->internal=$_POST[
'ext_jr_internal'];
98 echo $jrn->confirm($_POST,
true);
101 echo
'<span class="invoice">';
111 if ( $_POST[
'jrn_type'] ==
'VEN')
113 $jrn=
new Acc_Ledger_Sold(
$cn,$_POST[
'p_jrn']);
118 $op->suspend_receipt();
119 $op->suspend_strict();
122 $cn->exec_sql(
'update jrn set jr_pj_number=$1 where jr_id=$2',
123 array($oldpj,$_POST[
'ext_jr_id']));
124 $new_internal=$jrn->insert($_POST);
128 alert($e->getMessage());
136 $cn->exec_sql(
'delete from stock_goods where j_id in (select j_id from jrnx join jrn on (j_grpt=jr_grpt_id) where jr_id=$1)',
137 array($_POST[
'ext_jr_id']));
140 $cn->exec_sql(
'delete from jrnx where j_grpt in (select jr_grpt_id from jrn where jr_id=$1)',
141 array($_POST[
'ext_jr_id']));
144 $attach=
$cn->get_array(
'select jr_pj,jr_pj_name,jr_pj_type from jrn where jr_id=$1',
145 array($_POST[
'ext_jr_id']));
147 $cn->exec_sql(
'delete from jrn where jr_id=$1',array($_POST[
'ext_jr_id']));
148 $cn->exec_sql(
'update jrn set jr_id=$1,jr_internal=$2,jr_pj_number=$3 where jr_internal=$4',
149 array($_POST[
'ext_jr_id'],$_POST[
'ext_jr_internal'],$pj,$new_internal));
151 if ( $attach[0][
'jr_pj_name'] !=
'' && ! isset ($_POST[
'gen_invoice']))
153 $cn->exec_sql(
'update jrn set jr_pj=$1,jr_pj_type=$2,jr_pj_name=$3 where jr_id=$4',
154 array($attach[0][
'jr_pj'],$attach[0][
'jr_pj_type'],$attach[0][
'jr_pj_name'],$_POST[
'ext_jr_id']));
158 $cn->exec_sql(
'update quant_sold set qs_internal=$1 where qs_internal=$2',
159 array($_POST[
'ext_jr_internal'],$new_internal));
163 echo
'<h2 class="info"> Enregistrement </h2>';
164 $jr_id=$_POST[
'ext_jr_id'];
166 echo
"<h2 >"._(
'Opération sauvée');
167 if ( $jrn->pj !=
'') echo
' Piece : '.h($jrn->pj);
169 if ( strcmp($jrn->pj,$_POST[
'e_pj']) != 0 )
171 echo
'<h3 class="notice"> '._(
'Attention numéro pièce existante, elle a du être adaptée').
'</h3>';
174 printf (
'<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a><hr>',
176 $jrn->internal=$_POST[
'ext_jr_internal'];
177 echo $jrn->confirm($_POST,
true);
179 if (isset ($jrn->doc) )
181 echo
'<span class="invoice">';
189 $obj->save_extra($jr_id,$_POST);
197 if ( $_POST[
'jrn_type'] ==
'ODS')
199 $jrn=
new Acc_Ledger(
$cn,$_POST[
'p_jrn']);
203 $op->suspend_receipt();
204 $op->suspend_strict();
206 $_POST[
'e_pj']=microtime();
208 $new_internal=$jrn->internal;
212 alert($e->getMessage());
219 $cn->exec_sql(
'delete from jrnx where j_grpt in (select jr_grpt_id from jrn where jr_id=$1)',
220 array($_POST[
'ext_jr_id']));
223 $attach=
$cn->get_array(
'select jr_pj,jr_pj_name,jr_pj_type from jrn where jr_id=$1',
224 array($_POST[
'ext_jr_id']));
225 $cn->exec_sql(
'delete from jrn where jr_id=$1',array($_POST[
'ext_jr_id']));
226 $cn->exec_sql(
'update jrn set jr_id=$1,jr_internal=$2,jr_pj_number=$3 where jr_internal=$4',
227 array($_POST[
'ext_jr_id'],$_POST[
'ext_jr_internal'],$pj,$new_internal));
228 if ( $attach[0][
'jr_pj_name'] !=
'')
230 $cn->exec_sql(
'update jrn set jr_pj=$1,jr_pj_type=$2,jr_pj_name=$3 where jr_id=$4',
231 array($attach[0][
'jr_pj'],$attach[0][
'jr_pj_type'],$attach[0][
'jr_pj_name'],$_POST[
'ext_jr_id']));
241 if ( $_POST[
'jrn_type'] ==
'FIN')
248 if ( $user->check_jrn($p_jrn) !=
'W' )
249 throw new Exception (_(
'Accès interdit'),20);
251 if ( strlen(trim($e_bank_account)) == 0 )
252 throw new Exception(_(
'Vous n\'avez pas donné de banque'),11);
255 if ( isDate($e_date) == null )
257 throw new Exception(
'Date invalide', 2);
260 $fiche->get_by_qcode($e_bank_account);
261 if (
$fiche->empty_attribute(ATTR_DEF_ACCOUNT) ==
true)
262 throw new Exception(
'La fiche '.$e_bank_account.
'n\'a pas de poste comptable',8);
263 if (
$fiche->belong_ledger($p_jrn,
'cred') !=1 &&
$fiche->belong_ledger($p_jrn,
'deb') !=1 )
264 throw new Exception(
'La fiche '.$e_bank_account.
'n\'est pas accessible à ce journal',10);
266 $fiche->get_by_qcode($e_other);
267 if (
$fiche->empty_attribute(ATTR_DEF_ACCOUNT) ==
true)
268 throw new Exception(
'La fiche '.$e_other.
'n\'a pas de poste comptable',8);
269 if (
$fiche->belong_ledger($p_jrn,
'deb') !=1 )
270 throw new Exception(
'La fiche '.$e_other.
'n\'est pas accessible à ce journal',10);
271 if ( isNumber($ {
'e_other_amount'}) == 0 )
272 throw new Exception(
'La fiche '.$e_other.
'a un montant invalide ['.$e_other_amount.
']',6);
276 echo $e->getMessage();
287 throw new Exception (
'Période fermée');
290 $cn->exec_sql(
"update jrnx set j_montant=$1,j_jrn_def=$3,j_date=to_date($4,'DD.MM.YYYY'),j_tech_per=$5,j_tech_date=now() where j_grpt in (select jr_grpt_id from jrn where jr_id=$2)",array(abs($e_other_amount),$ext_jr_id,$p_jrn,$e_date,
$periode->p_id));
294 $cn->exec_sql(
"update jrn set jr_montant=$1,jr_comment=$2,jr_date=to_date($3,'DD.MM.YYYY'),jr_def_id=$4,jr_tech_per=$5,jr_pj_number=$6,jr_tech_date=now() where jr_id=$7",
295 array(abs($e_other_amount),$e_other_comment,$e_date,$p_jrn,
$periode->p_id,$e_pj,$ext_jr_id));
298 $fbank=
new Fiche(
$cn);
299 $fbank->get_by_qcode($e_bank_account);
300 $post_bank=$fbank->strAttribut(ATTR_DEF_ACCOUNT);
302 $fother=
new Fiche(
$cn);
303 $fother->get_by_qcode($e_other);
304 $post_other=$fother->strAttribut(ATTR_DEF_ACCOUNT);
305 if ($e_other_amount > 0 )
307 $cn->exec_sql(
'update jrnx set j_poste=$1,j_qcode=$2 where j_debit=false and j_grpt in (select jr_grpt_id from jrn where jr_id=$3)',array($post_other,$e_other,$ext_jr_id));
308 $cn->exec_sql(
'update jrnx set j_poste=$1,j_qcode=$2 where j_debit=true and j_grpt in (select jr_grpt_id from jrn where jr_id=$3)',array($post_bank,$e_bank_account,$ext_jr_id));
312 $cn->exec_sql(
'update jrnx set j_poste=$1,j_qcode=$2 where j_debit=false and j_grpt in (select jr_grpt_id from jrn where jr_id=$3)',array($post_bank,$e_bank_account,$ext_jr_id));
313 $cn->exec_sql(
'update jrnx set j_poste=$1,j_qcode=$2 where j_debit=true and j_grpt in (select jr_grpt_id from jrn where jr_id=$3)',array($post_other,$e_other,$ext_jr_id));
315 $cn->exec_sql(
'update quant_fin set qf_bank=$1,qf_amount=$3,qf_other=$2 where jr_id=$4',array($fbank->id,$fother->id,$e_other_amount,$ext_jr_id));
321 echo $e->getMessage();
324 echo h2info(
'Opération sauvée');
if($oPeriode->is_closed()==1) $op