altocompta/include/quick_writing.inc.php
2007-10-15 13:25:35 +00:00

131 lines
3.6 KiB
PHP

<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/* !\file
*/
/* \brief to write directly into the ledgers,the stock and the tables
* quant_purchase and quant_sold are not changed by this
*
*/
require_once ('class_acc_ledger.php');
$cn=DbConnect(dossier::id());
$id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
function show_direct_form($cn,$ledger,$p_array) {
$id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1;
// Show the predef operation
// Don't forget the p_jrn
echo '<form>';
echo dossier::hidden();
echo widget::hidden('p_action',$_REQUEST['p_action']);
echo '<input type="hidden" value="'.$id.'" name="p_jrn">';
$op=new Pre_operation($cn);
$op->p_jrn=$id;
$op->od_direct='t';
if ($op->count() != 0 )
echo widget::submit_button('use_opd','Utilisez une op.pr&eacute;d&eacute;finie');
echo $op->show_button();
echo '</form>';
echo '<form method="post" action="?">';
echo dossier::hidden();
echo widget::hidden('p_action',$_REQUEST['p_action']);
echo $ledger->show_form($p_array);
echo widget::submit_button('summary','Sauvez');
echo '</form>';
echo '</div>';
}
$ledger=new Acc_Ledger($cn,$id);
// no ledger selected, propose one
if ($id == -1 )
{
// Vide
echo '<FORM method="get" action="?">';
echo dossier::hidden();
echo widget::hidden('p_action',$_REQUEST['p_action']);
echo $ledger->select_ledger()->IOValue();
echo widget::submit_button('show_form','Choix du journal');
echo '</form>';
exit();
}
echo '<div class="u_content">';
echo '<h2 class="info"> Journal : '.$ledger->GetName().'</h2>';
echo widget::button_href('Autre journal','?p_action='.$_REQUEST['p_action'].'&'.dossier::get());
if ( isset($_GET['show_form']) || isset($_POST['correct_it']) ) {
show_direct_form($cn,$ledger,$_POST);
exit();
}
// reload with a predefined operation
//
if ( isset ($_GET['use_opd'])) {
$op=new Pre_op_advanced($cn);
$op->set_od_id($_REQUEST['pre_def']);
//$op->p_jrn=$id;
$p_post=$op->compute_array();
show_direct_form($cn,$ledger,$p_post);
exit();
}
if ( isset($_POST['summary'])) {
echo '<form method="post" action="?">';
echo $ledger->show_form($_POST,1);
echo dossier::hidden();
echo widget::hidden('p_action',$_REQUEST['p_action']);
echo widget::submit_button('save_it',"Sauver");
echo widget::submit_button('correct_it','Corriger');
$chk=new widget('checkbox');
$chk->selected=false;
echo "Sauvez l'op&eacute;ration ?";
echo $chk->IOValue('save_opd');
echo '</form>';
exit();
}
if ( isset($_POST['save_it' ])) {
$array=$_POST;
try {
$ledger->save($array);
} catch (AcException $e) {
echo '<script>alert (\''.$e->getMessage()."'); </script>";
show_direct_form($cn,$ledger,$_POST);
}
exit();
}