';
$msg_tva='Si le montant de TVA est égal à 0, il sera automatiquement calculé';
// First we show the menu
// If nothing is asked the propose a blank form
// to enter a new invoice
if ( ! isset ($_REQUEST['p_jrn'])) {
// no journal are selected so we select the first one
$p_jrn=GetFirstJrnIdForJrnType(dossier::id(),'ACH');
} else
{
$p_jrn=$_REQUEST['p_jrn'];
}
// for the back button
$retour="";
$h_url="";
if ( isset ($_REQUEST['url']))
{
$retour=sprintf('',urldecode($_REQUEST['url']));
$h_url=sprintf('',urldecode($_REQUEST['url']));
}
$sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
//--------------------------------------------------------------------------------
// use a predefined operation
//--------------------------------------------------------------------------------
if ( $sub_action=="use_opd" ) {
echo '
';
exit();
}
//-----------------------------------------------------
// If a list of depense is asked
//
if ( $sub_action == "list")
{
// show the menu with the list item selected
echo '
';
// Ask to update payment
if ( isset ( $_GET['paid']))
{
// reset all the paid flag because the checkbox is post only
// when checked
foreach ($_GET as $name=>$paid)
{
list($ad) = sscanf($name,"set_jr_id%d");
if ( $ad == null ) continue;
$sql="update jrn set jr_rapt='' where jr_id=$ad";
$Res=ExecSql($cn,$sql);
}
// set a paid flag for the checked box
foreach ($_GET as $name=>$paid)
{
list ($id) = sscanf ($name,"rd_paid%d");
if ( $id == null ) continue;
$paid=($paid=='on')?'paid':'';
$sql="update jrn set jr_rapt='$paid' where jr_id=$id";
$Res=ExecSql($cn,$sql);
}
}
echo '
';
// Ask to update payment
if ( isset ( $_POST['paid']))
{
// reset all the paid flag because the checkbox is post only
// when checked
foreach ($_POST as $name=>$paid)
{
list($ad) = sscanf($name,"set_jr_id%d");
if ( $ad == null ) continue;
$sql="update jrn set jr_rapt='' where jr_id=$ad";
$Res=ExecSql($cn,$sql);
}
// set a paid flag for the checked box
foreach ($_POST as $name=>$paid)
{
list ($id) = sscanf ($name,"rd_paid%d");
if ( $id == null ) continue;
$paid=($paid=='on')?'paid':'';
$sql="update jrn set jr_rapt='$paid' where jr_id=$id";
$Res=ExecSql($cn,$sql);
}
}
/* security put a filter on the ledger */
$available_ledger=$User->get_ledger_sql();
// Show list of unpaid sell
// Date - date of payment - Customer - amount
$sql=SQL_LIST_UNPAID_INVOICE_DATE_LIMIT." and $available_ledger ".
" and jrn_def_type='ACH'";
$offset=(isset($_GET['offset']))?$_GET['offset']:0;
$step=$_SESSION['g_pagesize'];
$page=(isset($_GET['offset']))?$_GET['page']:1;
list ($max_line,$list)=ListJrn($cn,0,$sql,null,$offset,1);
// $bar=jrn_navigation_bar($offset,$max_ligne,$step,$page);
$sql=SQL_LIST_UNPAID_INVOICE." and jrn_def_type='ACH' and $available_ledger";
list ($max_line2,$list2)=ListJrn($cn,0,$sql,null,$offset,1);
// Get the max line
$m=($max_line2>$max_line)?$max_line2:$max_line;
$bar2=jrn_navigation_bar($offset,$m,$step,$page);
echo '
';
//-----------------------------------------------------
// if we request to add an item
// the $_POST['add_item'] is set
// or if we ask to correct the invoice
if ( isset ($_POST['add_item']) || isset ($_POST["correct"]) )
{
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) != 2 ) {
NoAccess();
exit -1;
}
$nb_item=$_POST['nb_item'];
if ( isset ($_POST['add_item']))
$nb_item++;
// Submit button in the form
$submit='
';
$form=FormAchInput($cn,$p_jrn,$User->get_periode(),$_POST,$submit,false,$nb_item);
echo '
';
exit();
}
//-----------------------------------------------------
// we want to save the invoice
//
if ( isset($_POST['save']))
{
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) != 2 ) {
NoAccess();
exit -1;
}
$nb_number=$_POST["nb_item"];
if ( form_verify_input ($cn,$p_jrn,$User->get_periode(),$_POST,$nb_number) == true ) {
// we save the expense
list ($internal,$c)=RecordSell($cn,$_POST,$User,$p_jrn);
$form=FormAchView($cn,$p_jrn,$User->get_periode(),$_POST,"",$_POST['nb_item'],false);
echo '
';
echo $form;
echo '';
echo '';
return;
}
}
//-----------------------------------------------------
// we show the confirmation screen
//
if ( isset ($_POST['view_invoice']) )
{
// Check privilege
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) < 1 ) {
NoAccess();
exit -1;
}
$nb_number=$_POST["nb_item"];
$submit='';
$submit.='';
if ( form_verify_input ($cn,$p_jrn,$User->get_periode(),$_POST,$nb_number) == true ) {
// Should use a read only view instead of FormAch
// where we can check
$form=FormAchView($cn,$p_jrn,$User->get_periode(),$_POST,$submit,$nb_number);
} else {
// if something goes wrong, correct it
$submit='
';
$form=FormAchInput($cn,$p_jrn,$User->get_periode(),$_POST,$submit, false, $nb_number);
}
echo '
';
echo $form;
echo '
';
exit();
}
//-----------------------------------------------------
// By default we add a new invoice
if ( $p_jrn != -1 )
{
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) != 2 ) {
exit -1;
}
$jrn=new Acc_Ledger($cn, $p_jrn);
echo_debug('depense.inc.php',__LINE__,"Blank form");
// Submit button in the form
$submit='
';
// Show an empty form of invoice
$form=FormAchInput($cn,$p_jrn,$User->get_periode(),null,$submit,false,$jrn->getDefLine());
echo '