diff --git a/include/class_acc_account_ledger.php b/include/class_acc_account_ledger.php index 0ce0971bf..fca1d9654 100644 --- a/include/class_acc_account_ledger.php +++ b/include/class_acc_account_ledger.php @@ -365,7 +365,7 @@ class Acc_Account_Ledger if ( $old_exercice != '') { $progress=bcsub($sum_deb,$sum_cred); - + $side=" ".$this->get_amount_side($progress); echo "". "". td(''). @@ -373,7 +373,7 @@ class Acc_Account_Ledger "Totaux". "".nbm($sum_deb)."". "".nbm($sum_cred)."". - td(nbm(abs($progress)),'style="text-align:right"'). + td(nbm(abs($progress)).$side,'style="text-align:right"'). td(''). ""; $sum_cred=0; @@ -383,6 +383,7 @@ class Acc_Account_Ledger } } $progress=bcadd($progress,$tmp_diff); + $side=" ".$this->get_amount_side($progress); $sum_cred=bcadd($sum_cred,$op['cred_montant']); $sum_deb=bcadd($sum_deb,$op['deb_montant']); if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"'; @@ -395,7 +396,7 @@ class Acc_Account_Ledger "".h($op['description'])."". "".nbm($op['deb_montant'])."". "".nbm($op['cred_montant'])."". - td(nbm(abs($progress)),'style="text-align:right"'). + td(nbm(abs($progress)).$side,'style="text-align:right"'). td($let,' style="color:red;text-align:right"'). ""; @@ -403,19 +404,19 @@ class Acc_Account_Ledger } echo ''; $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur"; - $diff=abs(bcsub($sum_deb,$sum_cred)); - + $diff=bcsub($sum_deb,$sum_cred); + $side=" ".$this->get_amount_side($diff); echo "". "Totaux". "". "". "".nbm($sum_deb)."". "".nbm($sum_cred)."". - "".nbm($diff)."". + "".nbm(abs($diff)).$side."". ""; echo "$solde_type". - "".nbm($diff)."". + "".nbm(abs($diff))."". ""; echo ''; echo ''; @@ -424,7 +425,20 @@ class Acc_Account_Ledger return; } - + /** + * return the letter C if amount is > 0, D if < 0 or = + * @param type $p_amount + * @return string + */ + function get_amount_side($p_amount) + { + if ($p_amount == 0) + return "="; + if ($p_amount < 0) + return "C"; + if ($p_amount > 0) + return "D"; + } /*! * \brief Display HTML Table Header (button) * diff --git a/include/class_fiche.php b/include/class_fiche.php index cafd9eab0..18b781c30 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -1347,7 +1347,7 @@ class Fiche if ($old_exercice != '' ) { $progress=bcsub($sum_deb,$sum_cred); - + $side=" ".$this->get_amount_side($progress); echo "". "". td(''). @@ -1355,7 +1355,7 @@ class Fiche "Totaux". "".nbm($sum_deb)."". "".nbm($sum_cred)."". - td(nbm(abs($progress)),'style="text-align:right"'). + td(nbm(abs($progress)).$side,'style="text-align:right"'). td(''). ""; $sum_cred=0; @@ -1364,6 +1364,7 @@ class Fiche } } $progress=bcadd($progress,$tmp_diff); + $side=" ".$this->get_amount_side($progress); $sum_cred=bcadd($sum_cred,$op['cred_montant']); $sum_deb=bcadd($sum_deb,$op['deb_montant']); if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"'; @@ -1376,7 +1377,7 @@ class Fiche "".h($op['description'])."". "".nbm($op['deb_montant'])."". "".nbm($op['cred_montant'])."". - td(nbm(abs($progress)),'style="text-align:right"'). + td(nbm(abs($progress)).$side,'style="text-align:right"'). td($let,' style="color:red;text-align:right"'). ""; $old_exercice=$op['p_exercice']; @@ -1894,7 +1895,20 @@ class Fiche $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) select $1,ad_id,100 from fiche_detail where f_id=$2 and ad_id not in (select ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid)); $this->cn->commit(); } - + /** + * return the letter C if amount is > 0, D if < 0 or = + * @param type $p_amount + * @return string + */ + function get_amount_side($p_amount) + { + if ($p_amount == 0) + return "="; + if ($p_amount < 0) + return "C"; + if ($p_amount > 0) + return "D"; + } static function test_me() { $cn=new Database(dossier::id()); diff --git a/include/export_fiche_balance_csv.php b/include/export_fiche_balance_csv.php index a5161bf21..ee28014f7 100644 --- a/include/export_fiche_balance_csv.php +++ b/include/export_fiche_balance_csv.php @@ -98,6 +98,7 @@ else { $afiche[0] = array('fd_id' => $_REQUEST['cat']); } + $fic=new Fiche($cn); for ($e = 0; $e < count($afiche); $e++) { $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc'); @@ -142,6 +143,7 @@ else _('Débit'), _('Crébit'), _('Prog.'), + _('D/C'), _('Let.'), _("Diff Let.")); printf("\n"); @@ -159,7 +161,7 @@ else if ($row['j_debit'] == 't') { printf("%s;",nb($row['j_montant'])); - $amount_deb+=$row['j_montant']; + $amount_deb=bcadd($amount_deb,$row['j_montant']); $prog = bcadd($prog, $row['j_montant']); printf (";"); } @@ -167,10 +169,10 @@ else { printf(";"); printf("%s;",nb($row['j_montant'])); - $amount_cred+=$row['j_montant']; + $amount_cred=bcadd($amount_cred,$row['j_montant']); $prog = bcsub($prog, $row['j_montant']); } - printf ("%s;",nb($prog)); + printf ("%s;\"%s\";",abs(nb($prog)),$fic->get_amount_side($prog)); if ($row['letter'] != -1) { printf('"%s";',$row['letter']); @@ -187,8 +189,8 @@ else else $msg="soldé"; - printf(';;;"%s";%s;%s;%s', - $msg,nb($amount_deb),nb($amount_cred),nb($prog)); + printf(';;;"%s";%s;%s;%s;"%s"', + $msg,nb($amount_deb),nb($amount_cred),nb(abs($prog)),$fic->get_amount_side($prog)); printf("\n"); } } diff --git a/include/export_fiche_balance_pdf.php b/include/export_fiche_balance_pdf.php index 0ce2e1dda..2fdb433ba 100644 --- a/include/export_fiche_balance_pdf.php +++ b/include/export_fiche_balance_pdf.php @@ -143,7 +143,7 @@ else { $afiche[0] = array('fd_id' => $_REQUEST['cat']); } - + $fic=new Fiche($cn); for ($e = 0; $e < count($afiche); $e++) { $array = Fiche::get_fiche_def($cn,$afiche[$e]['fd_id'] , 'name_asc'); @@ -154,14 +154,14 @@ else { continue; } - $tab = array(13, 25, 55, 20, 20, 12, 20); - $align = array('L', 'L', 'L', 'R', 'R', 'R', 'R'); + $tab = array(12, 20, 10,78, 20, 20, 10, 20); + $align = array('L', 'C', 'L', 'L', 'R','R', 'R', 'R'); foreach ($array as $row_fiche) { - $row = new Fiche($cn, $row_fiche['f_id']); + $fic = 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('quick_code', $fic->strAttribut(ATTR_DEF_QUICKCODE)); $letter->set_parameter('start', $_GET['start']); $letter->set_parameter('end', $_GET['end']); // all @@ -195,15 +195,17 @@ else $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, 'Diff. Let.', 0, 0, 'R'); + $pdf->Cell($tab[2], 7, 'Int.'); + $pdf->Cell($tab[3], 7, 'Comm'); + $pdf->Cell($tab[4], 7, 'Montant', 0, 0, 'C'); + $pdf->Cell($tab[5], 7, 'Prog.', 0, 0, 'R'); + $pdf->Cell($tab[6], 7, 'Let.', 0, 0, 'R'); + $pdf->Cell($tab[7], 7, 'Diff. Let.', 0, 0, 'R'); $pdf->ln(); $amount_deb = 0; $amount_cred = 0; + $prog=0; for ($i = 0; $i < count($letter->content); $i++) { if ($i % 2 == 0) @@ -222,40 +224,44 @@ else $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); + $pdf->LongLine($tab[2], 4, $row['jr_internal'], 0, $align[1], $fill); + $pdf->LongLine($tab[3], 4, $row['jr_comment'], 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); + $prog=bcadd($prog,$row['j_montant']); + $pdf->Cell($tab[4], 4, sprintf('%s D', nbm($row['j_montant'])), 0, 0, $align[4], $fill); $amount_deb+=$row['j_montant']; - $pdf->Cell($tab[4], 4, "", 0, 0, 'C', $fill); + $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog)); + $pdf->Cell($tab[5], 4, $str_prog, 0, 0, $align[5], $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); + $prog=bcsub($prog,$row['j_montant']); + $pdf->Cell($tab[4], 4, sprintf('%s C', nbm($row['j_montant'])), 0, 0, $align[4], $fill); $amount_cred+=$row['j_montant']; + $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog)); + $pdf->Cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill); } if ($row['letter'] != -1) { - $pdf->Cell($tab[5], 4, $row['letter'], 0, 0, $align[5], $fill); + $pdf->Cell($tab[6], 4, $row['letter'], 0, 0, $align[6], $fill); // get sum for this lettering - $pdf->Cell($tab[6], 4, sprintf('%.2f', $row['letter_diff']), '0', '0', 'R', $fill); + $pdf->Cell($tab[7], 4, sprintf('%s', nbm($row['letter_diff'])), '0', '0', $align[7], $fill); } else - $pdf->Cell($tab[5], 4, "", 0, 0, 'R', $fill); + $pdf->Cell($tab[6], 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); + $debit = sprintf('Debit : %s', nbm($amount_deb)); + $credit = sprintf('Credit : %s', nbm($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)))); + $solde = sprintf('%s : %s', $s, nbm(abs(round($amount_cred - $amount_deb, 2)))); $pdf->Cell(0, 6, $debit, 0, 0, 'R'); $pdf->ln(4); diff --git a/include/export_gl_csv.php b/include/export_gl_csv.php index 8f6635132..aa9a99cd1 100644 --- a/include/export_gl_csv.php +++ b/include/export_gl_csv.php @@ -61,7 +61,7 @@ else { $cond_poste=''; $sql="select pcm_val from tmp_pcmn "; - if ($from_poste != '') + if ($from_poste != '') { $cond_poste = ' where '; $cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste).'\')'; @@ -69,7 +69,7 @@ else if ( $to_poste != '') { - if ( $cond_poste == '') + if ( $cond_poste == '') { $cond_poste = ' where pcm_val <= upper (\''.Database::escape_string($to_poste).'\')'; } @@ -100,10 +100,10 @@ $s=(isset($_REQUEST['solded']))?1:0; foreach ($a_poste as $poste) { - + $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']); - + $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s); // don't print empty account if ( count($array1) == 0 ) @@ -149,12 +149,12 @@ foreach ($a_poste as $poste) if ($detail['cred_montant'] > 0) { - $solde += $detail['cred_montant']; + $solde -= $detail['cred_montant']; $solde_c += $detail['cred_montant']; } if ($detail['deb_montant'] > 0) { - $solde -= $detail['deb_montant']; + $solde += $detail['deb_montant']; $solde_d += $detail['deb_montant']; } @@ -164,7 +164,8 @@ foreach ($a_poste as $poste) echo $detail['jr_pj_number'].";"; echo ($detail['deb_montant'] > 0 ? nb($detail['deb_montant']) : '').";"; echo ($detail['cred_montant'] > 0 ? nb($detail['cred_montant']) : '').";"; - echo nb($solde).";"; + echo nb(abs($solde)).";"; + echo $Poste->get_amount_side($solde); printf("\n"); } diff --git a/include/export_gl_pdf.php b/include/export_gl_pdf.php index c315a039b..4568f3133 100644 --- a/include/export_gl_pdf.php +++ b/include/export_gl_pdf.php @@ -139,17 +139,17 @@ foreach ($a_poste as $poste) if ($detail['cred_montant'] > 0) { - $solde += $detail['cred_montant']; + $solde -= $detail['cred_montant']; $solde_c += $detail['cred_montant']; } if ($detail['deb_montant'] > 0) { - $solde -= $detail['deb_montant']; + $solde += $detail['deb_montant']; $solde_d += $detail['deb_montant']; } $i = 0; - + $side=" ".$Poste->get_amount_side($solde); $pdf->Cell($width[$i], 6, shrink_date($detail['j_date_fmt']), 0, 0, $lor[$i]); $i++; $pdf->Cell($width[$i], 6, $detail['jr_internal'], 0, 0, $lor[$i]); @@ -165,7 +165,7 @@ foreach ($a_poste as $poste) $i++; $pdf->Cell($width[$i], 6, ($detail['cred_montant'] > 0 ? nbm( $detail['cred_montant']) : ''), 0, 0, $lor[$i]); $i++; - $pdf->Cell($width[$i], 6, nbm( $solde), 0, 0, $lor[$i]); + $pdf->Cell($width[$i], 6, nbm(abs( $solde)).$side, 0, 0, $lor[$i]); $i++; $pdf->Ln(); diff --git a/include/impress_fiche.inc.php b/include/impress_fiche.inc.php index af4f42df5..7405a9594 100644 --- a/include/impress_fiche.inc.php +++ b/include/impress_fiche.inc.php @@ -244,7 +244,7 @@ else } echo $export_csv; echo $export_pdf; - +$fiche=new Fiche($cn); for ($e = 0; $e < count($afiche); $e++) { $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc'); @@ -322,7 +322,8 @@ for ($e = 0; $e < count($afiche); $e++) $amount_cred+=$row['j_montant']; $prog = bcsub($prog, $row['j_montant']); } - echo td(nbm($prog), 'style="text-align:right"'); + $side=" ".$fiche->get_amount_side($prog); + echo td(nbm($prog).$side, 'style="text-align:right"'); if ($row['letter'] != -1) { $span_error=""; @@ -337,11 +338,11 @@ for ($e = 0; $e < count($afiche); $e++) echo ''; echo ''; echo td(_('Debit')); - echo td($amount_deb, ' style="font-weight:bold;text-align:right"'); + echo td(nbm($amount_deb), ' style="font-weight:bold;text-align:right"'); echo ''; echo ''; echo td(_('Credit')); - echo td($amount_cred, ' style="font-weight:bold;text-align:right"'); + echo td(nbm($amount_cred), ' style="font-weight:bold;text-align:right"'); echo ''; echo ''; if ($amount_deb > $amount_cred) @@ -349,7 +350,7 @@ for ($e = 0; $e < count($afiche); $e++) else $s = 'solde crediteur'; echo td($s); - echo td(abs(round($amount_cred - $amount_deb, 2)), ' style="font-weight:bold;text-align:right"'); + echo td(nbm(abs(round($amount_cred - $amount_deb, 2))), ' style="font-weight:bold;text-align:right"'); echo ''; echo '
'; } diff --git a/include/impress_gl_comptes.inc.php b/include/impress_gl_comptes.inc.php index 00a40695b..eb13f793c 100644 --- a/include/impress_gl_comptes.inc.php +++ b/include/impress_gl_comptes.inc.php @@ -207,14 +207,15 @@ if ( isset( $_REQUEST['bt_html'] ) ) if ($detail['cred_montant'] > 0) { - $solde=bcadd($solde, $detail['cred_montant']); + $solde=bcsub($solde, $detail['cred_montant']); $solde_c=bcadd($solde_c,$detail['cred_montant']); } if ($detail['deb_montant'] > 0) { - $solde = bcsub($solde,$detail['deb_montant']); + $solde = bcadd($solde,$detail['deb_montant']); $solde_d = bcadd($solde_d,$detail['deb_montant']); } + $side=" ".$Poste->get_amount_side($solde); $letter=($detail['letter']!=-1)?hi($detail['letter']):''; echo ' '.$detail['j_date_fmt'].' @@ -223,7 +224,7 @@ if ( isset( $_REQUEST['bt_html'] ) ) '.$detail['jr_pj_number'].' '.($detail['deb_montant'] > 0 ? nbm($detail['deb_montant']) : '').' '.($detail['cred_montant'] > 0 ? nbm($detail['cred_montant']) : '').' - '.nbm($solde).' + '.nbm(abs($solde)).$side.' '.$letter.' '; }