diff --git a/html/export.php b/html/export.php
index 3fef7ba5c..5829760fb 100644
--- a/html/export.php
+++ b/html/export.php
@@ -93,7 +93,7 @@ switch( $_GET['act'])
break;
case 'PDF/fiche_balance':
$user->can_request(IMPFIC,0);
- require_once('export_fiche_balance_csv.php');
+ require_once('export_fiche_balance_pdf.php');
exit();
break;
case 'CSV/report':
diff --git a/include/balance.inc.php b/include/balance.inc.php
index 16920e237..911b90b30 100644
--- a/include/balance.inc.php
+++ b/include/balance.inc.php
@@ -126,11 +126,12 @@ if (HtmlInput::default_value('lvl3',false,$_GET) !== false)
echo '
'.$ck_lev1->input().'Niveau 1';
echo ''.$ck_lev2->input().'Niveau 2';
echo ''.$ck_lev3->input().'Niveau 3';
-
-
-
echo '';
+$unsold=new ICheckBox('unsold');
+if (HtmlInput::default_value('unsold',false,$_GET) !== false)
+ $unsold->selected=true;
+
$from_poste=new IPoste();
$from_poste->name="from_poste";
@@ -156,7 +157,9 @@ echo $from_span->input();
echo " jusque :".$to_poste->input();
echo $to_span->input();
echo "";
-
+echo '';
+echo "Uniquement comptes non soldés ".$unsold->input();
+echo '
';
echo HtmlInput::submit("view","Visualisation");
echo '';
echo '
';
@@ -189,7 +192,7 @@ if ( isset ($_GET['view'] ) )
echo HtmlInput::hidden("from_poste",$_GET['from_poste']).
HtmlInput::hidden("to_poste",$_GET['to_poste']);
- echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3'));
+ echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3','unsold'));
echo "";
@@ -210,6 +213,7 @@ if ( isset ($_GET['view'] ) )
echo HtmlInput::hidden("from_poste",$_GET['from_poste']).
HtmlInput::hidden("to_poste",$_GET['to_poste']);
+ echo HtmlInput::get_to_hidden(array('unsold'));
echo "";
@@ -241,7 +245,8 @@ if ( isset($_GET['view'] ) )
}
$bal->from_poste=$_GET['from_poste'];
$bal->to_poste=$_GET['to_poste'];
-
+ if ( isset($_GET['unsold']))
+ $bal->unsold=true;
$row=$bal->get_row($_GET['from_periode'],
$_GET['to_periode']);
$periode=new Periode($cn);
diff --git a/include/class_acc_balance.php b/include/class_acc_balance.php
index 1d70d0e66..f718039b0 100644
--- a/include/class_acc_balance.php
+++ b/include/class_acc_balance.php
@@ -33,12 +33,14 @@ class Acc_Balance
var $jrn; /*!< idx of a table of ledger create by user->get_ledger */
var $from_poste; /*!< from_poste filter on the post */
var $to_poste; /*!< to_poste filter on the post*/
+ var $unsold; /*!< if true only the no solded account (saldo != 0) */
function Acc_Balance($p_cn)
{
$this->db=$p_cn;
$this->jrn=null;
$from_poste="";
$to_poste="";
+ $unsold=false;
}
@@ -135,6 +137,7 @@ class Acc_Balance
$a['sum_cred']=round($r['sum_cred'],2);
$a['solde_deb']=round(( $a['sum_deb'] >= $a['sum_cred'] )? $a['sum_deb']- $a['sum_cred']:0,2);
$a['solde_cred']=round(( $a['sum_deb'] <= $a['sum_cred'] )?$a['sum_cred']-$a['sum_deb']:0,2);
+ if ($this->unsold==true && $a['solde_cred']==0 && $a['solde_deb']==0) continue;
$array[$i]=$a;
$tot_cred+= $a['sum_cred'];
$tot_deb+= $a['sum_deb'];
diff --git a/include/export_balance_csv.php b/include/export_balance_csv.php
index 7f1ef6e79..4859562b3 100644
--- a/include/export_balance_csv.php
+++ b/include/export_balance_csv.php
@@ -70,6 +70,7 @@ case 2:
$bal->from_poste=$_GET['from_poste'];
$bal->to_poste=$_GET['to_poste'];
+if (isset($_GET['unsold'])) $bal->unsold=true;
$row=$bal->get_row($_GET['from_periode'],
$_GET['to_periode']);
diff --git a/include/export_balance_pdf.php b/include/export_balance_pdf.php
index 9b497f129..246275b04 100644
--- a/include/export_balance_pdf.php
+++ b/include/export_balance_pdf.php
@@ -41,7 +41,7 @@ $gDossier=dossier::id();
$cn=new Database($gDossier);
$rep=new Database();
-include ('class_user.php');
+require_once ('class_user.php');
$User=new User($cn);
$User->Check();
@@ -74,6 +74,7 @@ case 2:
$bal->from_poste=$_GET['from_poste'];
$bal->to_poste=$_GET['to_poste'];
+if (isset($_GET['unsold'])) $bal->unsold=true;
$array=$bal->get_row($from_periode,$to_periode);
@@ -126,8 +127,9 @@ for ($i=0;$ihasAttribute(ATTR_DEF_ACCOUNT) == false )
@@ -60,6 +60,11 @@ if ( $_GET['histo'] == 4 )
$oCard=new Fiche($cn,$aCard[$i]['f_id']);
$solde=$oCard->get_solde_detail($filter);
if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
+ /* only not purged card */
+ if ($_GET['histo'] == 5 && $solde['solde'] ==0) continue;
+ $side='';
+ if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.';
+ if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.';
printf('"%s";"%s";%s;%s;%s;"%s"',
$oCard->strAttribut(ATTR_DEF_QUICKCODE),
@@ -67,7 +72,7 @@ if ( $_GET['histo'] == 4 )
nb($solde['debit']),
nb($solde['credit']),
nb(abs($solde['solde'])),
- (($solde['solde']<0)?'CRED':'DEB'));
+ $side);
printf("\n");
}
}
diff --git a/include/export_fiche_balance_pdf.php b/include/export_fiche_balance_pdf.php
new file mode 100644
index 000000000..421b0fb9f
--- /dev/null
+++ b/include/export_fiche_balance_pdf.php
@@ -0,0 +1,240 @@
+category, export in PDF the history of a category
+ * of card
+ */
+
+// Security we check if user does exist and his privilege
+require_once('class_user.php');
+require_once('class_database.php');
+require_once('class_pdf.php');
+require_once('class_lettering.php');
+require_once('class_dossier.php');
+require_once('ac_common.php');
+
+/* Security */
+$gDossier=dossier::id();
+$cn=new Database($gDossier);
+$User=new User($cn);
+$User->Check();
+$User->check_dossier($gDossier);
+$User->can_request(IMPFIC,0);
+
+$pdf=new PDF($cn);
+$pdf->setDossierInfo(" Periode : ".$_GET['start']." - ".$_GET['end']);
+$pdf->AliasNbPages();
+$pdf->AddPage();
+$name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($_GET['cat']));
+$pdf->SetFont('DejaVu','BI',14);
+$pdf->Cell(0,8,$name,0,1,'C');
+$pdf->SetTitle($name,1);
+$pdf->SetAuthor('Phpcompta');
+/* balance */
+if ( $_GET['histo'] == 4 || $_GET['histo']==5)
+{
+ $fd=new Fiche_Def($cn,$_REQUEST['cat']);
+ if ( $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
+ {
+ $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a pas de balance");
+ //Save PDF to file
+ $fDate=date('dmy-Hi');
+ $pdf->Output("category-$fDate.pdf", 'I');
+ exit;
+ }
+ $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 ",array($_REQUEST['cat']));
+
+ if ( empty($aCard))
+ {
+ $pdf->Cell(0,10, "Aucune fiche trouvée");//Save PDF to file
+ $fDate=date('dmy-Hi');
+ $pdf->Output("category-$fDate.pdf", 'I');
+ exit;
+ }
+ $pdf->SetFont('DejaVuCond','',7);
+ $pdf->Cell(30,7,'Quick Code',0,0,'L',0);
+ $pdf->Cell(80,7,'Libellé',0,0,'L',0);
+ $pdf->Cell(20,7,'Débit',0,0,'R',0);
+ $pdf->Cell(20,7,'Crédit',0,0,'R',0);
+ $pdf->Cell(20,7,'Solde',0,0,'R',0);
+ $pdf->Cell(20,7,'D/C',0,0,'C',0);
+ $pdf->Ln();
+ $idx=0;
+ for ($i=0;$i < count($aCard);$i++)
+ {
+ if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) == null ) exit;
+ $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
+ " and j_date <= to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
+ $oCard=new Fiche($cn,$aCard[$i]['f_id']);
+ $solde=$oCard->get_solde_detail($filter);
+ if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
+ /* only not purged card */
+ if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit']) continue;
+
+ if ( $idx % 2 == 0 )
+ {
+ $pdf->SetFillColor(220,221,255);
+ $fill=1;
+ }
+ else
+ {
+ $pdf->SetFillColor(0,0,0);
+ $fill=0;
+ }
+ $idx++;
+ $side='';
+ if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.';
+ if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.';
+
+ $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
+ $pdf->Cell(80,7,$oCard->strAttribut(ATTR_DEF_NAME),0,0,'L',$fill);
+ $pdf->Cell(20,7,sprintf('%.02f',$solde['debit']),0,0,'R',$fill);
+ $pdf->Cell(20,7,sprintf('%.02f',$solde['credit']),0,0,'R',$fill);
+ $pdf->Cell(20,7,sprintf('%.02f',abs($solde['solde'])),0,0,'R',$fill);
+ $pdf->Cell(20,7,$side,0,0,'C',$fill);
+ $pdf->Ln();
+ }
+}
+else
+{
+ $array=Fiche::get_fiche_def($cn,$_GET['cat'],'name_asc');
+ /*
+ * You show now the result
+ */
+ if ($array == null )
+ {
+ exit();
+ }
+ $tab=array(13,25,55,20,20,12,20);
+ $align=array('L','L','L','R','R','R','R');
+
+ foreach($array as $row_fiche)
+ {
+ $row=new Fiche($cn,$row_fiche['f_id']);
+ $letter=new Lettering_Card($cn);
+ $letter->set_parameter('quick_code',$row->strAttribut(ATTR_DEF_QUICKCODE));
+ $letter->set_parameter('start',$_GET['start']);
+ $letter->set_parameter('end',$_GET['end']);
+ // all
+ if ( $_GET['histo'] == 0 )
+ {
+ $letter->get_all();
+ }
+
+ // lettered
+ if ( $_GET['histo'] == 1 )
+ {
+ $letter->get_letter();
+ }
+ // unlettered
+ if ( $_GET['histo'] == 2 )
+ {
+ $letter->get_unletter();
+ }
+ /* skip if nothing to display */
+ if (count($letter->content) == 0 ) continue;
+ $pdf->SetFont('DejaVuCond','',10);
+ $fiche=new Fiche($cn,$row_fiche['f_id']);
+ $pdf->Cell(0,7,$fiche->strAttribut(ATTR_DEF_NAME),1,1,'C');
+
+ $pdf->SetFont('DejaVuCond','',7);
+
+ $pdf->Cell($tab[0],7,'Date');
+ $pdf->Cell($tab[1],7,'ref');
+ $pdf->Cell($tab[1],7,'Int.');
+ $pdf->Cell($tab[2],7,'Comm');
+ $pdf->Cell(40,7,'Montant',0,0,'C');
+ $pdf->Cell($tab[5],7,'Let.',0,0,'R');
+ $pdf->Cell($tab[6],7,'Som. Let.',0,0,'R');
+ $pdf->ln();
+
+ $amount_deb=0;
+ $amount_cred=0;
+ for ($i=0;$icontent);$i++)
+ {
+ if ( $i % 2 == 0 )
+ {
+ $pdf->SetFillColor(220,221,255);
+ $fill=1;
+ }
+ else
+ {
+ $pdf->SetFillColor(0,0,0);
+ $fill=0;
+ }
+ $pdf->SetFont('DejaVuCond','',7);
+ $row=$letter->content[$i];
+ $str_date=shrink_date($row['j_date_fmt']);
+
+ $pdf->Cell($tab[0],4,$str_date,0,0,$align[0],$fill);
+ $pdf->Cell($tab[1],4,$row['jr_pj_number'],0,0,$align[1],$fill);
+ $pdf->Cell($tab[1],4,$row['jr_internal'],0,0,$align[1],$fill);
+ $pdf->Cell($tab[2],4,$row['jr_comment'],0,0,$align[2],$fill);
+ if ( $row['j_debit'] == 't')
+ {
+ $pdf->Cell($tab[3],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
+ $amount_deb+=$row['j_montant'];
+ $pdf->Cell($tab[4],4,"",0,0,'C',$fill);
+ }
+ else
+ {
+ $pdf->Cell($tab[3],4,"",0,0,'C',$fill);
+ $pdf->Cell($tab[4],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
+ $amount_cred+=$row['j_montant'];
+ }
+ if ($row['letter'] != -1 )
+ {
+ $pdf->Cell($tab[5],4,$row['letter'],0,0,$align[5],$fill);
+ // get sum for this lettering
+ $sql="select sum(j_montant) from jrnx where j_debit=$1 and j_id in ".
+ " (select j_id from jnt_letter join letter_deb using (jl_id) where jl_id=$2 union ".
+ " select j_id from jnt_letter join letter_cred using (jl_id) where jl_id=$3)";
+ $sum=$cn->get_value($sql,array($row['j_debit'],$row['letter'],$row['letter']));
+ $pdf->Cell($tab[6],4,sprintf('%.2f',$sum),'0','0','R',$fill);
+ }
+ else
+ $pdf->Cell($tab[5],4,"",0,0,'R',$fill);
+ $pdf->Ln();
+ }
+ $pdf->SetFillColor(0,0,0);
+ $pdf->SetFont('DejaVuCond','B',8);
+ $debit =sprintf('Debit : % 12.2f',$amount_deb);
+ $credit=sprintf('Credit : % 12.2f',$amount_cred);
+ if ( $amount_deb>$amount_cred) $s='solde débiteur';
+ else $s='solde crediteur';
+ $solde =sprintf('%s : % 12.2f',$s,(abs(round($amount_cred-$amount_deb,2))));
+
+ $pdf->Cell(0,6,$debit,0,0,'R');
+ $pdf->ln(4);
+ $pdf->Cell(0,6,$credit,0,0,'R');
+ $pdf->ln(4);
+ $pdf->Cell(0,6,$solde,0,0,'R');
+ $pdf->ln(4);
+
+ $pdf->Ln();
+ }
+}
+//Save PDF to file
+$fDate=date('dmy-Hi');
+$pdf->Output("category-$fDate.pdf", 'I');
+exit;
diff --git a/include/impress_fiche.inc.php b/include/impress_fiche.inc.php
index 4e35f4755..bc0405a5a 100644
--- a/include/impress_fiche.inc.php
+++ b/include/impress_fiche.inc.php
@@ -58,6 +58,7 @@ $histo->value=array(
array('value'=>2,'label'=>_('Historique non Lettré')),
array('value'=>3,'label'=>_('Résumé')),
array('value'=>4,'label'=>_('Balance')),
+ array('value'=>5,'label'=>_('Balance non soldée' ))
);
$histo->javascript='onchange="if (this.value==3) {
g("trstart").style.display="none";g("trend").style.display="none";}
@@ -113,7 +114,7 @@ if ( $_GET['histo'] == 3 )
}
$export_pdf='';
echo $export_pdf;
// Balance
-if ( $_GET['histo'] == 4 )
+if ( $_GET['histo'] == 4 || $_GET['histo']==5 )
{
if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) == null )
{
@@ -170,6 +171,8 @@ if ( $_GET['histo'] == 4 )
$oCard=new Fiche($cn,$aCard[$i]['f_id']);
$solde=$oCard->get_solde_detail($filter);
if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
+ /* only not purged card */
+ if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit']) continue;
$class='';
if ( $idx%2 == 0) $class='class="odd"';
$idx++;