226 lines
5.0 KiB
C++
Executable File
226 lines
5.0 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <defmask.h>
|
|
#include <execp.h>
|
|
#include <progind.h>
|
|
#include <relation.h>
|
|
#include <reputils.h>
|
|
#include <sheet.h>
|
|
#include <textset.h>
|
|
#include <utility.h>
|
|
|
|
#include "..\ve\rcondv.h"
|
|
#include "..\mg\codcorr.h"
|
|
#include "..\mg\anamag.h"
|
|
|
|
#include "ps0830.h"
|
|
#include "ps0830100a.h"
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
// Recordset esporta_listino
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
class TEsporta_listino_recordset : public TCSV_recordset
|
|
{
|
|
protected:
|
|
virtual const TToken_string& sheet_head() const;
|
|
virtual unsigned int columns() const { return 6; }
|
|
|
|
public:
|
|
virtual bool set(unsigned int fld, const TVariant& var);
|
|
TEsporta_listino_recordset();
|
|
};
|
|
|
|
const TToken_string& TEsporta_listino_recordset::sheet_head() const
|
|
{
|
|
TToken_string& head = get_tmp_string();
|
|
head = HR("Codice EAN@13|Prezzo@10R|Cassa@5|Descrizione@13|Sc.per.@5|Sc.mon.@5|Cod.Off.@5");
|
|
return head;
|
|
}
|
|
|
|
bool TEsporta_listino_recordset::set(unsigned int column, const TVariant& var)
|
|
{
|
|
if (!var.is_empty())
|
|
{
|
|
TString80 str;
|
|
if (var.is_date())
|
|
{
|
|
const TDate data = var.as_date();
|
|
str = data.string(full,'-', full, full, amg_date);
|
|
}
|
|
else
|
|
str << var;
|
|
str.replace('|', '/');
|
|
return TCSV_recordset::set(column, TVariant(str));
|
|
}
|
|
|
|
return TCSV_recordset::set(column, var);
|
|
}
|
|
|
|
TEsporta_listino_recordset::TEsporta_listino_recordset()
|
|
: TCSV_recordset("CSV(\":\")")
|
|
{
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
// Mask esporta_listino
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
class TEsporta_listino_mask : public TAutomask
|
|
{
|
|
private:
|
|
void serialize(bool bSave);
|
|
void esporta_listino(const bool anteprima);
|
|
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TEsporta_listino_mask();
|
|
~TEsporta_listino_mask();
|
|
};
|
|
|
|
void TEsporta_listino_mask::serialize(bool bSave)
|
|
{
|
|
const char* defpar = "ps";
|
|
TConfig ini(CONFIG_DITTA, defpar);
|
|
for (int i = fields()-1; i >= 0; i--)
|
|
{
|
|
TMask_field& f = fld(i);
|
|
const TFieldref* fr = f.field();
|
|
if (fr != NULL)
|
|
{
|
|
if (bSave)
|
|
fr->write(ini, defpar, f.get());
|
|
else
|
|
f.set(fr->read(ini, defpar));
|
|
}
|
|
}
|
|
}
|
|
|
|
TEsporta_listino_mask::TEsporta_listino_mask()
|
|
: TAutomask("ps0830100a")
|
|
{
|
|
serialize(false);
|
|
}
|
|
|
|
TEsporta_listino_mask::~TEsporta_listino_mask()
|
|
{
|
|
serialize(true);
|
|
}
|
|
|
|
bool TEsporta_listino_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
{
|
|
switch (f.dlg())
|
|
{
|
|
case DLG_OK:
|
|
if (e == fe_button)
|
|
esporta_listino(false);
|
|
break;
|
|
case DLG_PREVIEW:
|
|
if (e == fe_button)
|
|
esporta_listino(true);
|
|
break;
|
|
case F_PATH:
|
|
if (e == fe_init || e == fe_modify)
|
|
{
|
|
TFilename file = f.get();
|
|
file.add("aggiorna.bat");
|
|
enable(DLG_OK, file.exist());
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TEsporta_listino_mask::esporta_listino(const bool anteprima)
|
|
{
|
|
// query su listino
|
|
TString query;
|
|
query << "USE RCONDV\n";
|
|
query << "SELECT (CATVEN=\"DE\") && (RCONDV.PREZZO>\"0\") && (CODCORR.CODARTALT!=\"\")\n";
|
|
query << "JOIN CODCORR INTO CODART==CODRIGA NRIGA=1\n";
|
|
query << "JOIN ANAMAG INTO CODART==CODRIGA\n";
|
|
TISAM_recordset listino(query);
|
|
|
|
TEsporta_listino_recordset csv;
|
|
|
|
const int items = listino.items();
|
|
|
|
TProgind pi(items, TR("Estrazione listino..."), true, true);
|
|
for (bool ok = listino.move_first(); ok; ok = listino.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
real prezzo = listino.get(RCONDV_PREZZO).as_real();
|
|
if (prezzo > ZERO)
|
|
{
|
|
csv.new_rec("");
|
|
csv.set(0, listino.get("CODCORR.CODARTALT"));
|
|
prezzo = prezzo*CENTO;
|
|
prezzo.round();
|
|
csv.set(1, TVariant(prezzo));
|
|
csv.set(2, listino.get("ANAMAG.REPARTO[2,3]"));
|
|
csv.set(3, listino.get("ANAMAG.DESCR[1,12]"));
|
|
csv.set(4, "0");
|
|
csv.set(5, "0");
|
|
csv.set(6, "0");
|
|
}
|
|
} //for(move_first()..
|
|
csv.sort();
|
|
|
|
if (anteprima)
|
|
{
|
|
TRecordset_sheet sheet(csv, TR("Elenco di controllo"));
|
|
sheet.run();
|
|
}
|
|
else
|
|
{
|
|
TFilename file = get(F_PATH);
|
|
file.add(get(F_NAME));
|
|
csv.save_as(file, fmt_text);
|
|
|
|
if (yesno_box(TR("Generazione listino terminata.\nProcedere con l'invio?")))
|
|
{
|
|
file = get(F_PATH); file.add("aggiorna.bat");
|
|
if (file.exist())
|
|
{
|
|
TExternal_app a(file);
|
|
a.run(false,false,false);
|
|
}
|
|
else
|
|
error_box(TR("Impossibile procedere con l'invio,\nnon esiste l'applicazione %s"), (const char*)file);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEsporta_listino applicazione
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEsporta_listino_app : public TSkeleton_application
|
|
{
|
|
protected:
|
|
virtual const char* extra_modules() const { return "ve"; }
|
|
virtual void main_loop();
|
|
};
|
|
|
|
void TEsporta_listino_app::main_loop()
|
|
{
|
|
open_files(LF_RCONDV, LF_ANAMAG, LF_CODCORR, 0);
|
|
TEsporta_listino_mask m;
|
|
m.run();
|
|
}
|
|
|
|
int ps0830100(int argc, char* argv[])
|
|
{
|
|
TEsporta_listino_app app;
|
|
app.run(argc, argv, TR("Esporta listino"));
|
|
return 0;
|
|
}
|