/*$Id:$*/
/*19.05.2022	19.01.2004	Белых А.И.	sozkomw.c
Формирование комментария 
*/
#include <errno.h>
#include "buhg_g.h"

extern SQL_baza bd;

void sozkomw(class iceb_u_str *koment,
char *komentprov, //Коментарий из проводки
char *kto, //Из какой подсистемы сделана проводка
char *kodop) //Код операции
{
char   strsql[512];
SQL_str row1;

koment->new_plus(komentprov);
if(koment->getdlinna() > 1)
  return;
  
//if(koment[0] == '\0' && kto[0] == '\0' )
if(koment->getdlinna() <= 1 && kto[0] == '\0' )
  return;
SQLCURSOR cur1;
memset(strsql,'\0',sizeof(strsql));
if(iceb_u_SRAV(kto,ICEB_MP_MATU,0) == 0)
 {
  sprintf(strsql,"select naik from Prihod where kod='%s'",kodop);
  if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
    koment->new_plus(row1[0]);
  else
   {
    sprintf(strsql,"select naik from Rashod where kod='%s'",kodop);
    if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
     koment->new_plus(row1[0]);
   }
 }

if(iceb_u_SRAV(kto,ICEB_MP_PPOR,0) == 0)
 {
  sprintf(strsql,"select naik from Opltp where kod='%s'",kodop);
  if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
     koment->new_plus(row1[0]);
 }

if(iceb_u_SRAV(kto,ICEB_MP_KASA,0) == 0)
 {
  sprintf(strsql,"select naik from Кasop1 where kod='%s'",kodop);
  if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
     koment->new_plus(row1[0]);
  else
   {
    sprintf(strsql,"select naik from Kasop2 where kod='%s'",kodop);
    if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
     koment->new_plus(row1[0]);
   }
 }

if(iceb_u_SRAV(kto,ICEB_MP_USLUGI,0) == 0)
 {
  sprintf(strsql,"select naik from Usloper1 where kod='%s'",kodop);
  if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
     koment->new_plus(row1[0]);
  else
   {
    sprintf(strsql,"select naik from Usloper2 where kod='%s'",kodop);
    if(sql_readkey(&bd,strsql,&row1,&cur1) == 1)
     koment->new_plus(row1[0]);
   }
 }
   

}
