$type = Compta_Categories::RECETTES;
$error = false;
+$debug = "_POST=".print_r($_POST, true);
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 .= "<br/>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'],
{
$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'],
$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'],
}
$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
{
$tpl->display('admin/compta/operations/saisir.tpl');
-?>
\ No newline at end of file
+?>