X-Git-Url: https://git.cyclocoop.org/?p=garradin.git;a=blobdiff_plain;f=www%2Fadmin%2Fcompta%2Foperations%2Fsaisir.php;h=57a91dddd54ee744f3a4ac16bed7cbd4dd4eec57;hp=8847861c872ea751c1ffeb42b76d2729dffe1cec;hb=f7ee0ae730f47bfef173c394fa4db71a22dece61;hpb=1ab3343a95ed3ef4958d91dfbf49372dce8a092e diff --git a/www/admin/compta/operations/saisir.php b/www/admin/compta/operations/saisir.php index 8847861..57a91dd 100644 --- a/www/admin/compta/operations/saisir.php +++ b/www/admin/compta/operations/saisir.php @@ -27,6 +27,7 @@ else $type = Compta_Categories::RECETTES; $error = false; +$debug = "_POST=".print_r($_POST, true); if (!empty($_POST['save'])) { @@ -40,12 +41,34 @@ if (!empty($_POST['save'])) { if (is_null($type)) { + $fluxs = []; + $solde = 0.0; + for ($n=0; array_key_exists('compte_'.$n, $_POST); $n++) + { + $compte = $_POST['compte_'.$n]; + if (array_key_exists('montant_'.$n, $_POST)) { + $montant = $_POST['montant_'.$n]; + if ($montant == 0.0) + { + continue; + } + else + { + $solde += $montant; + $fluxs[] = ['compte' => $compte, 'montant' => $montant]; + } + } else { + if ($solde != 0.0) { + $fluxs[] = ['compte' => $compte, 'montant' => - $solde]; + } + break; + } + } + $debug .= "
fluxs = ".print_r($fluxs, true); $id = $journal->add([ 'libelle' => utils::post('libelle'), - 'montant' => utils::post('montant'), 'date' => utils::post('date'), - 'compte_credit' => utils::post('compte_credit'), - 'compte_debit' => utils::post('compte_debit'), + 'fluxs' => $fluxs, 'numero_piece' => utils::post('numero_piece'), 'remarques' => utils::post('remarques'), 'id_auteur' => $user['id'], @@ -55,10 +78,10 @@ if (!empty($_POST['save'])) { $id = $journal->add([ 'libelle' => utils::post('libelle'), - 'montant' => utils::post('montant'), 'date' => utils::post('date'), - 'compte_credit' => utils::post('compte1'), - 'compte_debit' => utils::post('compte2'), + 'fluxs' => + [ ['compte'=>utils::post('compte1'), 'montant' => - utils::post('montant')] + , ['compte'=>utils::post('compte2'), 'montant' => utils::post('montant')] ], 'numero_piece' => utils::post('numero_piece'), 'remarques' => utils::post('remarques'), 'id_auteur' => $user['id'], @@ -123,12 +146,12 @@ if (!empty($_POST['save'])) $id = $journal->add([ 'libelle' => utils::post('libelle'), - 'montant' => utils::post('montant'), 'date' => utils::post('date'), + 'fluxs' => + [ ['compte'=>$credit, 'montant' => - utils::post('montant')] + , ['compte'=>$debit, 'montant' => utils::post('montant')] ], 'moyen_paiement'=> ($type === 'dette') ? null : utils::post('moyen_paiement'), 'numero_cheque' => ($type === 'dette') ? null : utils::post('numero_cheque'), - 'compte_credit' => $credit, - 'compte_debit' => $debit, 'numero_piece' => utils::post('numero_piece'), 'remarques' => utils::post('remarques'), 'id_categorie' => ($type === 'dette') ? null : (int)$cat['id'], @@ -155,12 +178,17 @@ if (!empty($_POST['save'])) } $tpl->assign('error', $error); - +$tpl->assign('debug', $debug."END"); $tpl->assign('type', $type); -if ($type === null) +if (is_null($type)) { $tpl->assign('comptes', $comptes->listTree()); + $tpl->assign('fluxs', + [ 0 => ['compte' => '', 'montant' => 0.0] + , 1 => ['compte' => '', 'montant' => 0.0] + ] + ); } else { @@ -191,4 +219,4 @@ $tpl->assign('ok', (int) utils::get('ok')); $tpl->display('admin/compta/operations/saisir.tpl'); -?> \ No newline at end of file +?>