Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@21812 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			234 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			234 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <dongle.h>
 | 
						|
#include <modaut.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <recset.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "../mg/anamag.h"
 | 
						|
#include "../mg/codcorr.h"
 | 
						|
 | 
						|
#include "ps0330200a.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////
 | 
						|
//  MASCHERA
 | 
						|
///////////////////////////////////////////////
 | 
						|
class TDisp_by_ftp_mask : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TDisp_by_ftp_mask();
 | 
						|
};
 | 
						|
 | 
						|
TDisp_by_ftp_mask::TDisp_by_ftp_mask() : TAutomask("ps0330200a")
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
bool TDisp_by_ftp_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  /*switch(o.dlg())
 | 
						|
  {
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }*/
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////
 | 
						|
//  RECORDSET
 | 
						|
///////////////////////////////////////////////
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////
 | 
						|
//  APPLICAZIONE
 | 
						|
///////////////////////////////////////////////
 | 
						|
class TDisp_by_ftp : public TSkeleton_application
 | 
						|
{
 | 
						|
  TDisp_by_ftp_mask*  _mask;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool check_autorization() const {return false;}
 | 
						|
  virtual const char * extra_modules() const {return "ve";}
 | 
						|
  virtual bool create();
 | 
						|
  virtual void main_loop();
 | 
						|
 | 
						|
  const TString& find_ean(const TString& codart); 
 | 
						|
 | 
						|
public:
 | 
						|
  void elabora();
 | 
						|
 | 
						|
};
 | 
						|
 | 
						|
//ritorna il codice EAN13 dell'articolo in input; in caso di codici multipli ritorna l'ultimo...
 | 
						|
//..dovrebbe essere il più nuovo...forse...
 | 
						|
const TString& TDisp_by_ftp::find_ean(const TString& codart)
 | 
						|
{
 | 
						|
  TString ean_query;
 | 
						|
  ean_query << "USE CODCORR";
 | 
						|
  ean_query << "\nSELECT (TIPO==1)";
 | 
						|
  ean_query << "\nFROM CODART=#CODART";
 | 
						|
  ean_query << "\nTO CODART=#CODART";
 | 
						|
  TISAM_recordset ean_recset(ean_query);
 | 
						|
  ean_recset.set_var("#CODART", codart);
 | 
						|
  const bool ok = ean_recset.move_first();
 | 
						|
 | 
						|
  TString& ean_code = get_tmp_string();
 | 
						|
  if (ok)
 | 
						|
    ean_code = ean_recset.get(CODCORR_CODARTALT).as_string();
 | 
						|
 | 
						|
  return ean_code;
 | 
						|
}
 | 
						|
 | 
						|
void TDisp_by_ftp::elabora()
 | 
						|
{
 | 
						|
  //preparazione file .txt che verrà completato in locale con i dati estratti e poi spedito alla..
 | 
						|
  //..directory ftp specificata
 | 
						|
  TFilename file_txt;
 | 
						|
  file_txt.tempdir();
 | 
						|
  file_txt.add(_mask->get(F_FILENAME));
 | 
						|
  file_txt.ext(".txt");
 | 
						|
  ofstream file_output(file_txt);
 | 
						|
 | 
						|
  TString query;
 | 
						|
  //se è stato selezionato un listino (ovvero il programma funziona come richiesto dalla ModelAssistance)..
 | 
						|
  const TString4 codlis = _mask->get(F_CODLIS);
 | 
						|
  const bool usa_listino = codlis.full();
 | 
						|
  if (usa_listino)
 | 
						|
  {
 | 
						|
    query << "USE RCONDV";
 | 
						|
    query << "\nJOIN 109 INTO ANNOES=#ANNO CODART==CODRIGA";
 | 
						|
    query << "\nJOIN ANAMAG INTO CODART==CODRIGA";
 | 
						|
    query << "\nJOIN UMART INTO CODART==CODRIGA NRIGA=1";
 | 
						|
    query << "\nFROM TIPO=L COD=#CODLIS TIPORIGA=A";
 | 
						|
    query << "\nTO TIPO=L COD=#CODLIS TIPORIGA=A";
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
  //crea il recordset da esportare
 | 
						|
  //esporta dati dalle giacenze di magazzino, l'anagrafica articolo, l'unità di misura
 | 
						|
    query << "USE 109";
 | 
						|
    query << "\nBY ANAMAG.CODART";
 | 
						|
    query << "\nJOIN ANAMAG INTO CODART==CODART";
 | 
						|
    query << "\nJOIN UMART INTO CODART=CODART NRIGA=1";
 | 
						|
    query << "\nFROM ANNOES=#ANNO";
 | 
						|
    query << "\nTO ANNOES=#ANNO";
 | 
						|
  }
 | 
						|
 | 
						|
  TISAM_recordset recset(query);
 | 
						|
 | 
						|
  const TDate today(TODAY);
 | 
						|
  const long anno = today.year();
 | 
						|
  recset.set_var("#ANNO", anno);
 | 
						|
 | 
						|
  if (usa_listino)
 | 
						|
    recset.set_var("#CODLIS", codlis);
 | 
						|
 | 
						|
  const long items = recset.items();
 | 
						|
 | 
						|
  TProgind pi(items, "Elaborazione in corso...", true, true);
 | 
						|
 | 
						|
  TToken_string record;
 | 
						|
  //aggiunge l'intestazione (ultima moda delle richieste)
 | 
						|
  record.add("CodProdotto|DescProdotto|CodProdProduttore|Qta|QtaArr|DataArr|CostoTerashop|CostoListino|DataCodifica|CodCategoria|DescCategoria|CodMarca|DescMarca|Stato|CodEAN|");
 | 
						|
  file_output << record << endl;
 | 
						|
 | 
						|
  for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | 
						|
  {
 | 
						|
    if (!pi.addstatus(1))
 | 
						|
      break;
 | 
						|
 | 
						|
    record.cut(0);
 | 
						|
 | 
						|
    const TString80 codart = recset.get("ANAMAG.CODART").as_string();
 | 
						|
    record.add(codart);                                           //codart
 | 
						|
 | 
						|
    TString descr = recset.get("ANAMAG.DESCR").as_string();
 | 
						|
    descr << " " << recset.get("ANAMAG.DESCRAGG").as_string();
 | 
						|
    descr.left(100);
 | 
						|
    record.add(descr);                                            //descr
 | 
						|
 | 
						|
    TString80 manufacturer_codart = codart;
 | 
						|
    //manufacturer_codart.ltrim(3); richiesta assolutamente del cazzo che chiederanno di cambiare
 | 
						|
    record.add(manufacturer_codart);                              //co. prodotto produttore
 | 
						|
 | 
						|
    const real giac = recset.get("109.GIAC").as_real();
 | 
						|
    const long int_giac = giac.integer();
 | 
						|
    record.add(int_giac);                                         //quantita' disponibile
 | 
						|
 | 
						|
    record.add("");                                               //qta in arrivo (integer)
 | 
						|
    record.add("");                                               //data arrivo prevista (gg/mm/aaaa)
 | 
						|
 | 
						|
    const real prezzo = recset.get("UMART.PREZZO").as_real();     //prezzo (con ',' separatore decimale; se vogliono ',' -> stringa())
 | 
						|
    const TString80 str_prezzo = prezzo.string();
 | 
						|
    record.add(str_prezzo);
 | 
						|
 | 
						|
    record.add(str_prezzo);                                       //prezzo al pubblico
 | 
						|
 | 
						|
    TString16 str_data = today.string();
 | 
						|
    str_data.replace('-', '/');
 | 
						|
    record.add(today.string());                                   //data creazione
 | 
						|
 | 
						|
    const TString& grmerc = recset.get("ANAMAG.GRMERC").as_string();
 | 
						|
    record.add(grmerc);                                           //gruppo merceologco
 | 
						|
    const TString& grmerc_descr = cache().get("GMC", codart, "S0");
 | 
						|
    record.add(grmerc_descr);                                     //descrizione grmerc
 | 
						|
 | 
						|
    const TString& marca = codart.left(3);
 | 
						|
    record.add(marca);                                            //marca
 | 
						|
    const TString& descr_marca = cache().get(LF_ANAMAG, marca, ANAMAG_DESCR);
 | 
						|
    record.add(descr_marca);                                      //descrizione marca
 | 
						|
 | 
						|
    record.add("");                                               //stato del prodotto (1 carattere: Nuovo,In esurimento, Fine serie, Obsoleto)
 | 
						|
 | 
						|
    const TString& ean_code = find_ean(codart);
 | 
						|
    record.add(ean_code);                                         //codart per l'EAN
 | 
						|
 | 
						|
    //crittura del record sull'ofstream
 | 
						|
    file_output << record << endl;
 | 
						|
  }
 | 
						|
 | 
						|
  //chiusura dell'ofstream
 | 
						|
  file_output.close();
 | 
						|
 | 
						|
  //spostamento del file locale nella directory di destinazione
 | 
						|
  TFilename dst_file = _mask->get(F_FTP_PATH);
 | 
						|
  dst_file.add(file_txt.name());
 | 
						|
  if (!xvt_fsys_fcopy(file_txt, dst_file))
 | 
						|
    warning_box("Impossibile spostare il file nella cartella ftp indicata");
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
bool TDisp_by_ftp::create()
 | 
						|
{
 | 
						|
  //se non ha VE non può proseguire
 | 
						|
  if (!has_module(VEAUT))
 | 
						|
    return error_box(TR("Modulo non autorizzato"));
 | 
						|
  Tdninst dninst;
 | 
						|
  if (!dninst.can_I_run(true))
 | 
						|
    return error_box(TR("Programma non autorizzato!"));
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
void TDisp_by_ftp::main_loop()
 | 
						|
{
 | 
						|
  _mask = new TDisp_by_ftp_mask;
 | 
						|
  if (_mask->run() != K_QUIT)
 | 
						|
    elabora();
 | 
						|
 | 
						|
  delete _mask;
 | 
						|
  _mask = NULL;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int ps0330200 (int argc, char **argv)
 | 
						|
{
 | 
						|
  TDisp_by_ftp a;
 | 
						|
  a.run(argc,argv, TR("Esportazione disponibilita'"));
 | 
						|
  return true;
 | 
						|
} |