/*$Id:$*/
/*13.07.2022	22.03.2017	Белых А.И.	iceb_t_nn9_start_s.c
Вставка сумм по документу в шапку документа
*/
#include "buhl.h"

void iceb_t_nn9_start_s(const char *imaf,int lnds,double suma_dok,double suma_nds,double suma_vt)
{
char imaf_tmp[64];
char strsql[1024];
class iceb_tu_str stroka("");
double suma[12];
memset(suma,'\0',sizeof(suma));

suma[0]=suma_dok;

suma[1]=suma_nds;
 
if(lnds == 0) /*20 процентов*/
 {
  suma[2]=suma_nds;
  suma[5]=suma_dok-suma_nds;
 }

if(lnds == 4)/*7 процентов*/
 {
  suma[3]=suma_nds;
  suma[6]=suma_dok;
 } 

if(lnds == 5)/*14 процентов*/
 {
  suma[4]=suma_nds;
  suma[7]=suma_dok;
 } 


if(lnds == 2) /*0 процентов экспорт*/
 {
  suma[8]=suma_dok;
 }

if(lnds == 1) /*0 процентов на територии Украины*/
 {
  suma[9]=suma_dok;

 }

if(lnds == 3) /*освобождено от НДС*/
 {
  suma[10]=suma_dok;
 }


/*возвратная тара*/
suma[11]=suma_vt;

class iceb_fopen fil_ff;
if(fil_ff.start(imaf,"r") != 0)
 return;

sprintf(imaf_tmp,"nn%d.tmp",getpid());
class iceb_fopen fil_tmp;

if(fil_tmp.start(imaf_tmp,"w") != 0)
 return;
int nom_str=0;
int nom_sum=0;

while(iceb_tu_fgets(&stroka,fil_ff.ff) == 0)
 {
//  printw("%s",stroka.ravno());
    
  switch(++nom_str)
   {
    case 31:
    case 33:
    case 35:
    case 37:
    case 39:
    case 41:
    case 43:
    case 45:
    case 47:
    case 49:
    case 51:
    case 52:
     if(suma[nom_sum] != 0.)
      {
       sprintf(strsql,"%17.2f",suma[nom_sum]);
       iceb_tu_vstav(&stroka,strsql,163,181,1);
      }
     nom_sum++;
     break;
   }
  fprintf(fil_tmp.ff,"%s",stroka.ravno());
 }

fil_ff.end();
fil_tmp.end();
unlink(imaf);
rename(imaf_tmp,imaf);
}