Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione Partners 2.0 patch 335 git-svn-id: svn://10.65.10.50/trunk@10496 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			385 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			385 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>     
 | 
						||
#include <automask.h>     
 | 
						||
#include <config.h>     
 | 
						||
#include <defmask.h>
 | 
						||
#include <execp.h>
 | 
						||
#include <fstream.h>
 | 
						||
#include <golem.h>     
 | 
						||
#include <prefix.h>
 | 
						||
                    
 | 
						||
#include <clifo.h>                    
 | 
						||
#include <doc.h>                    
 | 
						||
#include <rdoc.h>                    
 | 
						||
                    
 | 
						||
#include "ve6400a.h"
 | 
						||
#include "velib.h"
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Maschera principale
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TScontrino_mask : public TAutomask
 | 
						||
{
 | 
						||
  bool _ini_loaded;    
 | 
						||
  TFilename _ini_name;
 | 
						||
 | 
						||
protected:
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
  
 | 
						||
  // Funzioni di invio ai registratori di cassa conosciuti
 | 
						||
  bool send_er400_data(bool extra);
 | 
						||
  bool send_scr_data();
 | 
						||
  
 | 
						||
public:                         
 | 
						||
  bool load_ini();
 | 
						||
  bool save_ini(KEY k);
 | 
						||
  
 | 
						||
  bool load_profile();
 | 
						||
  bool save_profile();
 | 
						||
  
 | 
						||
  bool send_data();
 | 
						||
 | 
						||
  TScontrino_mask();
 | 
						||
  virtual ~TScontrino_mask();
 | 
						||
};
 | 
						||
 | 
						||
bool TScontrino_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  switch (o.dlg())
 | 
						||
  {
 | 
						||
  case DLG_SAVEREC:
 | 
						||
    if (e == fe_button)
 | 
						||
    {
 | 
						||
      if (send_data() && _ini_loaded)
 | 
						||
        stop_run(K_AUTO_ENTER);
 | 
						||
    }
 | 
						||
    break;  
 | 
						||
  default:
 | 
						||
    break;
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TScontrino_mask::load_profile()
 | 
						||
{
 | 
						||
  TFilename f;
 | 
						||
  f =::firm2dir(-1);    // Directory dati
 | 
						||
  f.add("config");      // Directory config
 | 
						||
  f.add(source_file()); // Nome Maschera
 | 
						||
  f.ext("ini");         // Estensione
 | 
						||
  TConfig ini(f, "Main");
 | 
						||
  set(F_REGISTRATORE, ini.get("Registratore"));
 | 
						||
  set(F_SALUTI, ini.get("Saluti", NULL, -1, "Arrivederci  Grazie!"));
 | 
						||
  return TRUE; 
 | 
						||
}
 | 
						||
 | 
						||
bool TScontrino_mask::save_profile()
 | 
						||
{
 | 
						||
  TFilename f;
 | 
						||
  f =::firm2dir(-1);    // Directory dati
 | 
						||
  f.add("config");      // Directory config
 | 
						||
  f.add(source_file()); // Nome Maschera
 | 
						||
  f.ext("ini");         // Estensione
 | 
						||
  TConfig ini(f, "Main");
 | 
						||
  ini.set("Registratore", get(F_REGISTRATORE));
 | 
						||
  ini.set("Saluti", get(F_SALUTI));
 | 
						||
  return TRUE; 
 | 
						||
}
 | 
						||
 | 
						||
bool TScontrino_mask::load_ini()
 | 
						||
{ 
 | 
						||
  _ini_loaded = FALSE;
 | 
						||
   
 | 
						||
  const TApplication& a = main_app();
 | 
						||
  const int argc = a.argc();
 | 
						||
  if (argc <= 2)
 | 
						||
    return FALSE;
 | 
						||
  
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);  
 | 
						||
 | 
						||
  const TString& arg = a.argv(2);
 | 
						||
  if ((arg[0] != '-' && arg[0] != '/') || (arg[1] != 'i' && arg[1] != 'I'))
 | 
						||
    return FALSE;
 | 
						||
    
 | 
						||
  _ini_name = arg.mid(2);
 | 
						||
  if (_ini_name.blank() && argc > 3)  
 | 
						||
    _ini_name = a.argv(3);
 | 
						||
    
 | 
						||
  if (!_ini_name.exist())  
 | 
						||
    return FALSE;
 | 
						||
  
 | 
						||
  TString16 para;
 | 
						||
  para.format("%d", LF_DOC);
 | 
						||
  TString tmp;
 | 
						||
  
 | 
						||
  TDocumento doc;
 | 
						||
  
 | 
						||
  TConfig ini(_ini_name, para);
 | 
						||
  TAssoc_array& vars = ini.list_variables();
 | 
						||
  FOR_EACH_ASSOC_STRING(vars, obj, key, str)
 | 
						||
  {
 | 
						||
    if (*str == '"')
 | 
						||
    {
 | 
						||
      tmp = str;
 | 
						||
      tmp.strip("\"");
 | 
						||
      str = tmp;
 | 
						||
    }
 | 
						||
    doc.put(key, str);
 | 
						||
  }
 | 
						||
  
 | 
						||
  const TString& cofi = doc.clifor().get(CLI_COFI);
 | 
						||
  if (cofi.not_empty())
 | 
						||
    set(F_COFI, cofi);
 | 
						||
  else
 | 
						||
  {
 | 
						||
    const TString& piva = doc.clifor().get(CLI_PAIV);
 | 
						||
    set(F_COFI, piva);
 | 
						||
  }  
 | 
						||
  
 | 
						||
  for (int i = 1; ; i++)
 | 
						||
  {
 | 
						||
    para.format("%d,%d", LF_RIGHEDOC, i);
 | 
						||
    if (!ini.set_paragraph(para))
 | 
						||
      break;          
 | 
						||
    
 | 
						||
    const TString& tiporiga = ini.get(RDOC_TIPORIGA);
 | 
						||
    TRiga_documento& rdoc = doc.new_row(tiporiga);
 | 
						||
    TAssoc_array& vars = ini.list_variables();
 | 
						||
    FOR_EACH_ASSOC_STRING(vars, obj, key, str)
 | 
						||
    {
 | 
						||
      if (*str == '"')
 | 
						||
      {
 | 
						||
        tmp = str;
 | 
						||
        tmp.strip("\"");
 | 
						||
        str = tmp;
 | 
						||
      }
 | 
						||
      rdoc.put(key, str);
 | 
						||
    }
 | 
						||
    
 | 
						||
    if (tiporiga.not_empty() && rdoc.is_articolo())  
 | 
						||
    {
 | 
						||
      TToken_string& row = sheet.row(-1);
 | 
						||
      row = rdoc.get(RDOC_CODARTMAG);
 | 
						||
      row.add(rdoc.get(RDOC_DESCR));
 | 
						||
      row.add(rdoc.get(RDOC_QTA));
 | 
						||
      row.add(rdoc.prezzo(TRUE, TRUE).string());
 | 
						||
      row.add("1");
 | 
						||
    }  
 | 
						||
  }
 | 
						||
 | 
						||
  _ini_loaded = sheet.items() > 0;
 | 
						||
  return _ini_loaded;
 | 
						||
}
 | 
						||
 | 
						||
bool TScontrino_mask::save_ini(KEY k)
 | 
						||
{ 
 | 
						||
  bool ok = _ini_loaded && _ini_name.exist();
 | 
						||
  if (ok)
 | 
						||
  {
 | 
						||
    TConfig ini(_ini_name, "Main");
 | 
						||
    ini.set("Result", k == K_ENTER ? "OK" : "CANCEL");
 | 
						||
    ini.set("Error", "0");
 | 
						||
    
 | 
						||
    const TRectype& eld = cache().get("%ELD", ini.get("Action"));
 | 
						||
    const TString& stato_finale = eld.get("S4");
 | 
						||
    if (stato_finale.not_empty())
 | 
						||
    {
 | 
						||
      TString16 para; para.format("%d", LF_DOC);
 | 
						||
      ini.set(DOC_STATO, stato_finale, para);
 | 
						||
    }  
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TScontrino_mask::send_er400_data(bool extra)
 | 
						||
{ 
 | 
						||
/*  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  const int rows = sheet.items();
 | 
						||
  if (rows <= 0)
 | 
						||
    return FALSE;
 | 
						||
 | 
						||
  TMask m("Modalita' di pagamento", 1, 26, 8);
 | 
						||
  m.add_radio(101, 0, "", 1, 0, 24, 
 | 
						||
              "CASH|TICK|ASS|CARD|CRT", 
 | 
						||
              "Contanti|Buoni|Assegno|Carta di Credito|Credito");
 | 
						||
  m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
 | 
						||
  m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
 | 
						||
  if (m.run() != K_ENTER)
 | 
						||
    return FALSE;
 | 
						||
 | 
						||
  const char* server = "Sidcomm95";
 | 
						||
  const char* topic = server; // Ignoranza totale delle regole di buona programmazione DDE!        
 | 
						||
  TDDE smart;
 | 
						||
  if (!smart.initiate(server, topic))
 | 
						||
    return error_box("Impossibile stabilire una comunicazione DDE con %s", server);
 | 
						||
 | 
						||
  TString80 cmd, tmp;         
 | 
						||
 | 
						||
  const int text_len = extra ? 18 : 15;
 | 
						||
  TParagraph_string para("", text_len);
 | 
						||
  
 | 
						||
  const int pos_descr  = sheet.cid2index(F_DESCART);
 | 
						||
  const int pos_prezzo = sheet.cid2index(F_PREZZO);
 | 
						||
  const int pos_rep    = sheet.cid2index(F_REPARTO);
 | 
						||
  const int pos_qta    = sheet.cid2index(F_QTA);
 | 
						||
  for (int r = 0; r < rows; r++)
 | 
						||
  {                 
 | 
						||
    const TToken_string& row = sheet.row(r);
 | 
						||
    cmd = "[PLU,";
 | 
						||
 | 
						||
    row.get(pos_descr, tmp); 
 | 
						||
    if (tmp.blank()) continue;
 | 
						||
      
 | 
						||
    tmp.replace(',', ' '); tmp.replace('[', '('); tmp.replace(']', ')');
 | 
						||
    para = tmp;
 | 
						||
    cmd << para.get(0);
 | 
						||
    
 | 
						||
    real price; row.get(pos_prezzo, price);
 | 
						||
    cmd << ',' << price;
 | 
						||
    
 | 
						||
    int rep;  row.get(pos_rep, rep);
 | 
						||
    if (rep <= 0 || rep > 25) rep = 1;
 | 
						||
    cmd << ',' << rep;             
 | 
						||
 | 
						||
    real qta; row.get(pos_qta, qta);
 | 
						||
    cmd << ',' << qta << ']';
 | 
						||
    
 | 
						||
    smart.execute(cmd);
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (extra)
 | 
						||
  {        
 | 
						||
    tmp = get(F_COFI);
 | 
						||
    if (tmp.not_empty())
 | 
						||
    {
 | 
						||
      cmd = "[CODF,";
 | 
						||
      cmd << get(F_COFI) << ']';
 | 
						||
      smart.execute(cmd);
 | 
						||
    }
 | 
						||
    
 | 
						||
    para = get(F_SALUTI);
 | 
						||
    if (!para.blank())
 | 
						||
    {             
 | 
						||
      for (int i = 1; i <= 2; i++)
 | 
						||
      {
 | 
						||
        tmp = para.get();
 | 
						||
        tmp.replace(',', ' '); tmp.replace('[', '('); tmp.replace(']', ')');
 | 
						||
        if (!tmp.blank())
 | 
						||
        {
 | 
						||
          cmd.format("[TXT%d,%s]", i,  (const char*)tmp);
 | 
						||
          smart.execute(cmd);
 | 
						||
        }  
 | 
						||
      }  
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  cmd = "[";
 | 
						||
  cmd << m.get(101) << ']';
 | 
						||
  smart.execute(cmd);
 | 
						||
  
 | 
						||
  smart.terminate();*/
 | 
						||
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
bool TScontrino_mask::send_scr_data()
 | 
						||
{ 
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  const int rows = sheet.items();
 | 
						||
  if (rows <= 0)
 | 
						||
    return FALSE; 
 | 
						||
  
 | 
						||
  ofstream o("input.scr");
 | 
						||
  
 | 
						||
  o<<"$max_num_dept=20;"<<endl;
 | 
						||
  
 | 
						||
  const int pos_code   = sheet.cid2index(F_CODART);
 | 
						||
  const int pos_prezzo = sheet.cid2index(F_PREZZO);
 | 
						||
  const int pos_rep    = sheet.cid2index(F_REPARTO);
 | 
						||
  const int pos_qta    = sheet.cid2index(F_QTA);
 | 
						||
         
 | 
						||
  TString codart, grmerc, descr;
 | 
						||
  real prezzo, qta;
 | 
						||
         
 | 
						||
  for (int r = 0; r < rows; r++)
 | 
						||
  {                                         
 | 
						||
    const TToken_string& row = sheet.row(r);
 | 
						||
    
 | 
						||
    row.get(pos_code, codart);
 | 
						||
        
 | 
						||
    grmerc = cache().get(LF_ANAMAG,codart).get(ANAMAG_GRMERC);
 | 
						||
    
 | 
						||
    descr = cache().get("GMC",grmerc).get("S0");      //trova nella tabella GMC il record descrizione che corrisponde
 | 
						||
                                                      //a grmerc e prende il campo S0, che <20> la descrizione estesa del
 | 
						||
                                                      //gruppo merceologico codificato da grmerc
 | 
						||
    grmerc = grmerc.mid(1,2);                                                  
 | 
						||
    descr.cut(15);
 | 
						||
                                                      
 | 
						||
    row.get(pos_prezzo,prezzo);
 | 
						||
    row.get(pos_qta,qta);
 | 
						||
    real tot = qta * prezzo;
 | 
						||
    tot.round(0);                                         
 | 
						||
                     
 | 
						||
    
 | 
						||
    o << "plud,c,:" << descr << ",n" << grmerc << ",p" << tot.string("@@@@@@@@@@@") << ";"<<endl;
 | 
						||
  }
 | 
						||
    
 | 
						||
  o<<"cash;"<<endl;
 | 
						||
  o.close();                                         //forza la chiusura del file 
 | 
						||
  
 | 
						||
  TExternal_app a("pos1 input.scr");
 | 
						||
  a.run(FALSE,FALSE);
 | 
						||
  
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
bool TScontrino_mask::send_data()
 | 
						||
{           
 | 
						||
  bool ok = FALSE;
 | 
						||
  const TString& reg = get(F_REGISTRATORE);
 | 
						||
  if (reg == "ER400")
 | 
						||
    ok = send_er400_data(TRUE); 
 | 
						||
  if (reg == "ER315")
 | 
						||
    ok = send_er400_data(FALSE); 
 | 
						||
  if (reg == "SCR")
 | 
						||
    ok = send_scr_data();  
 | 
						||
  return ok;  
 | 
						||
}
 | 
						||
 | 
						||
TScontrino_mask::TScontrino_mask() 
 | 
						||
               : TAutomask("ve6400a"), _ini_loaded(FALSE) 
 | 
						||
{ load_profile(); }
 | 
						||
 | 
						||
TScontrino_mask::~TScontrino_mask() 
 | 
						||
{ save_profile(); }
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Applicazione principale
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TCoulthard : public TSkeleton_application
 | 
						||
{ 
 | 
						||
public:
 | 
						||
  virtual void main_loop();
 | 
						||
};        
 | 
						||
 | 
						||
void TCoulthard::main_loop()
 | 
						||
{                
 | 
						||
  open_files(LF_TAB, LF_TABCOM, LF_DOC, LF_RIGHEDOC, NULL);
 | 
						||
  open_files(LF_ANAMAG, LF_CLIFO, LF_CFVEN, LF_OCCAS, NULL);
 | 
						||
  TScontrino_mask m;
 | 
						||
  const bool loaded = m.load_ini();
 | 
						||
  KEY k = m.run();
 | 
						||
  if (loaded)
 | 
						||
    m.save_ini(k);
 | 
						||
}
 | 
						||
 | 
						||
int ve6400(int argc, char** argv)
 | 
						||
{
 | 
						||
  TCoulthard app;
 | 
						||
  app.run(argc, argv, "Scontrino");
 | 
						||
  return 0;
 | 
						||
}
 |