/*$Id: iceb_t_akt_sv.c,v 5.6 2013/05/17 14:56:27 sasa Exp $*/
/*05.11.2009	26.01.2007	Белых А.И.	iceb_t_akt_sv.c
Распечатка информации по акту сверки
*/
#include "buhl.h"

void iceb_t_akt_sv_it(double deb_start,double kre_start,double deb_oborot,double kre_oborot,double deb_ob_mes,double kre_ob_mes,FILE *ff);


void iceb_t_akt_sv(class iceb_t_akt_sverki *iceb_t_akt_svr,FILE *ff, /*с месячными итогами*/
FILE *ff_bi) /*Без месячных итогов*/
{

iceb_t_zagsh(iceb_t_akt_svr->shet.ravno(),ff);
iceb_t_zagsh(iceb_t_akt_svr->shet.ravno(),ff_bi);

if(iceb_t_akt_svr->start_saldo_deb > iceb_t_akt_svr->start_saldo_kre)
 {
  fprintf(ff,"%02d.%02d.%4d %-*.*s %10.2f %10s| |\n",
  iceb_t_akt_svr->dn,iceb_t_akt_svr->mn,iceb_t_akt_svr->gn,
  iceb_tu_kolbait(20,gettext("Сальдо начальное")),iceb_tu_kolbait(20,gettext("Сальдо начальное")),gettext("Сальдо начальное"),
  iceb_t_akt_svr->start_saldo_deb," ");

  fprintf(ff_bi,"%02d.%02d.%4d %-*.*s %10.2f %10s| |\n",
  iceb_t_akt_svr->dn,iceb_t_akt_svr->mn,iceb_t_akt_svr->gn,
  iceb_tu_kolbait(20,gettext("Сальдо начальное")),iceb_tu_kolbait(20,gettext("Сальдо начальное")),gettext("Сальдо начальное"),
  iceb_t_akt_svr->start_saldo_deb," ");
 }
else
 {
  fprintf(ff,"%02d.%02d.%4d %-*.*s %10s %10.2f| |\n",
  iceb_t_akt_svr->dn, iceb_t_akt_svr->mn, iceb_t_akt_svr->gn,
  iceb_tu_kolbait(20,gettext("Сальдо начальное")),iceb_tu_kolbait(20,gettext("Сальдо начальное")),gettext("Сальдо начальное"),
  " ",iceb_t_akt_svr->start_saldo_kre);
  fprintf(ff_bi,"%02d.%02d.%4d %-*.*s %10s %10.2f| |\n",
  iceb_t_akt_svr->dn, iceb_t_akt_svr->mn, iceb_t_akt_svr->gn,
  iceb_tu_kolbait(20,gettext("Сальдо начальное")),iceb_tu_kolbait(20,gettext("Сальдо начальное")),gettext("Сальдо начальное"),
  " ",iceb_t_akt_svr->start_saldo_kre);
 }
fprintf(ff,"\
------------------------------------------------------ ---------------------------------------------------\n");
fprintf(ff_bi,"\
------------------------------------------------------ ---------------------------------------------------\n");
short d,m,g;
short mz=0,gz=0;
double deb_oborot=0.;
double kre_oborot=0.;
double deb_ob_mes=0.;
double kre_ob_mes=0.;
double deb,kre;
 
for(int ii=0; ii < iceb_t_akt_svr->data_nomd.kolih(); ii++)
 {
  iceb_tu_rsdat(&d,&m,&g,iceb_t_akt_svr->data_nomd.ravno(ii),1);
  if(mz != m || gz != g)
   {
    if(mz != 0)
       iceb_t_akt_sv_it(iceb_t_akt_svr->start_saldo_deb,iceb_t_akt_svr->start_saldo_kre,deb_oborot,kre_oborot,deb_ob_mes,kre_ob_mes,ff);
    deb_ob_mes=kre_ob_mes=0.;    
    mz=m;
    gz=g;
   }     
  
  deb=iceb_t_akt_svr->suma_deb.ravno(ii);
  kre=iceb_t_akt_svr->suma_kre.ravno(ii);
  
  fprintf(ff,"%02d.%02d.%4d %-*.*s %10.2f %10.2f| |\n",
  d,m,g,
  iceb_tu_kolbait(20,iceb_t_akt_svr->koment.ravno(ii)),iceb_tu_kolbait(20,iceb_t_akt_svr->koment.ravno(ii)),iceb_t_akt_svr->koment.ravno(ii),
  deb,kre);

  fprintf(ff_bi,"%02d.%02d.%4d %-*.*s %10.2f %10.2f| |\n",
  d,m,g,
  iceb_tu_kolbait(20,iceb_t_akt_svr->koment.ravno(ii)),iceb_tu_kolbait(20,iceb_t_akt_svr->koment.ravno(ii)),iceb_t_akt_svr->koment.ravno(ii),
  deb,kre);

  fprintf(ff,"\
------------------------------------------------------ ---------------------------------------------------\n");
  fprintf(ff_bi,"\
------------------------------------------------------ ---------------------------------------------------\n");
  deb_oborot+=deb;
  kre_oborot+=kre;
  deb_ob_mes+=deb;
  kre_ob_mes+=kre;
 }

iceb_t_akt_sv_it(iceb_t_akt_svr->start_saldo_deb,iceb_t_akt_svr->start_saldo_kre,deb_oborot,kre_oborot,deb_ob_mes,kre_ob_mes,ff);
iceb_t_akt_sv_it(iceb_t_akt_svr->start_saldo_deb,iceb_t_akt_svr->start_saldo_kre,deb_oborot,kre_oborot,deb_ob_mes,kre_ob_mes,ff_bi);

}
/*********************/
/*Выдача итога*/
/*********************/

void iceb_t_akt_sv_it(double deb_start,double kre_start,
double deb_oborot,double kre_oborot,
double deb_ob_mes,double kre_ob_mes,
FILE *ff)
{

double brr=deb_start+deb_oborot;
double krr=kre_start+kre_oborot;

if(deb_ob_mes != 0. || kre_ob_mes != 0.)
 {
  fprintf(ff,"%*s %10.2f %10.2f| |\n",
  iceb_tu_kolbait(31,gettext("Оборот за месяц")),gettext("Оборот за месяц"),deb_ob_mes,kre_ob_mes);
 }

 fprintf(ff,"%*s %10.2f %10.2f| |\n",
 iceb_tu_kolbait(31,gettext("Оборот за период")),gettext("Оборот за период"),deb_oborot,kre_oborot);


 fprintf(ff,"%*s %10.2f %10.2f| |\n",
 iceb_tu_kolbait(31,gettext("Сальдо раз-нутое")),gettext("Сальдо раз-нутое"),brr,krr);

if(brr >= krr)
 {
  brr=brr-krr;
  fprintf(ff,"%*s %10.2f %10s| |\n",
  iceb_tu_kolbait(31,gettext("Сальдо свернутое")),gettext("Сальдо свернутое"),brr," ");
 }
else
 {
  brr=krr-brr;
  fprintf(ff,"%*s %10s %10.2f| |\n",
  iceb_tu_kolbait(31,gettext("Сальдо свернутое")),gettext("Сальдо свернутое")," ",brr);
 }
}
