',urldecode($_REQUEST['url']));
$h_url=sprintf('',urldecode($_REQUEST['url']));
}
$sub_action=(isset($_REQUEST['sa']))?$_REQUEST['sa']:"";
//-----------------------------------------------------
// If a list of invoice is asked
//
if ( $sub_action == "list")
{
// Check privilege
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) < 1 ) {
NoAccess();
exit -1;
}
// show the menu with the list item selected
echo '
';
echo ShowMenuJrnUser($gDossier,'VEN',0,'
Liste
');
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 '
';
//--------------------------------------------------------------------------------
// use a predefined operation
//--------------------------------------------------------------------------------
if ( $sub_action=="use_opd" ) {
$op=new Pre_op_ven($cn);
$op->set_od_id($_REQUEST['pre_def']);
$p_post=$op->compute_array();
echo_debug(__FILE__.':'.__LINE__.'- ','p_post = ',$p_post);
$form=FormVenInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$p_post,false,$p_post['nb_item']);
echo '
';
echo $form;
echo '
';
exit();
}
//-----------------------------------------------------
// 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_new_invoice"]) )
{
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) != 2 ) {
NoAccess();
exit -1;
}
$nb_item=$_POST['nb_item'];
if ( isset ($_POST['add_item']))
$nb_item++;
$form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),$_POST,false,$nb_item);
echo '
';
echo $form;
echo '
';
exit();
}
//-----------------------------------------------------
// we want to save the invoice and to generate a invoice
//
if ( isset($_POST['record_and_print_invoice']))
{
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) != 2 ) {
NoAccess();
exit -1;
}
$nb_number=$_POST['nb_item'];
// First we save the invoice, the internal code will be used to change the description
// and upload the file
if ( form_verify_input($cn,$p_jrn,$User->GetPeriode(),$_POST,$nb_number)== true) {
list ($internal,$e)=RecordInvoice($cn,$_POST,$User,$p_jrn);
$form=FormVenteView($cn,$p_jrn,$User->GetPeriode(),$_POST,$_POST['nb_item'],'noform','');
echo '
';
echo '
Opération '.$internal.' enregistré
';
echo $form;
echo '';
// Show the details of the encoded invoice
// and the url of the invoice
if ( isset($_POST['gen_invoice']))
{
$doc=new Document($cn);
$doc->f_id=$_POST['e_client'];
$doc->md_id=$_POST['gen_doc'];
$doc->ag_id=0;
$str_file=$doc->Generate();
// Move the document to the jrn
$doc->MoveDocumentPj($internal);
// Update the comment with invoice number
$sql="update jrn set jr_comment='Facture ".$doc->d_number."' where jr_internal='$internal'";
ExecSql($cn,$sql);
echo $str_file;
}
} else {
echo("A cause d'erreur la facture ne peut-ètre validé ");
$form=FormVenteView($cn,$_GET['p_jrn'],$User->GetPeriode(),$_POST,$nb_number,"form");
}
echo '';
// Button return
printf ('',
$p_jrn,dossier::get());
exit();
}
//-----------------------------------------------------
// we show the confirmation screen it is proposed here to generate the
// invoice
if ( isset ($_POST['view_invoice']) )
{
// Check privilege
if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) < 1 ) {
NoAccess();
exit -1;
}
$nb_number=$_POST["nb_item"];
if ( form_verify_input($cn,$p_jrn,$User->GetPeriode(),$_POST,$nb_number) == true)
{
$form=FormVenteView($cn,$p_jrn,$User->GetPeriode(),$_POST,$nb_number);
} else {
// Check failed : invalid date or quantity
echo_error("Cannot validate ");
$form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),$_POST,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('facture.inc.php.php',__LINE__,"Blank form");
// Show an empty form of invoice
$form=FormVenInput($cn,$p_jrn,$User->GetPeriode(),null,false,$jrn->GetDefLine());
echo '