Files correlati : cg0.exe cg0700a.msk cg0700b.msk Bug : Commento: Trasformazione occasionali in clienti/fornitori
440 lines
11 KiB
C++
Executable File
440 lines
11 KiB
C++
Executable File
#include <execp.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <relapp.h>
|
|
#include "..\ve\velib.h"
|
|
|
|
#include "cg0.h"
|
|
#include "cg0700a.h"
|
|
#include "cg0700b.h"
|
|
|
|
#include <comuni.h>
|
|
#include <clifo.h>
|
|
#include <cfven.h>
|
|
#include "cfban.h"
|
|
#include <doc.h>
|
|
#include <occas.h>
|
|
#include <pconti.h>
|
|
#include <postman.h>
|
|
#include <saldi.h>
|
|
#include <automask.h>
|
|
#include <validate.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TCheck_PIVA_mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TOccasionali_mask : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
void update_ban(const char * tipo, long codcf, const TRectype & recdoc);
|
|
void occ2clifor(const char * tipo);
|
|
TOccasionali_mask() : TAutomask("cg0700a") { }
|
|
};
|
|
|
|
void TOccasionali_mask::update_ban(const char * tipo, long codcf, const TRectype & recdoc)
|
|
{
|
|
TString iban = recdoc.get(DOC_IBAN);
|
|
|
|
if (iban.full())
|
|
{
|
|
TToken_string key;
|
|
bool updated = false;
|
|
|
|
key.add(tipo);
|
|
key.add(codcf);
|
|
key.add(tipo == "C" ? "N" : "V");
|
|
|
|
TRecord_array vs_ban(key, LF_CFBAN);
|
|
const int vsrow = vs_ban.rows();
|
|
bool found = false;
|
|
|
|
for (int i = 1; !found && i <= vsrow; i++)
|
|
{
|
|
TRectype & ban = (TRectype &)vs_ban.row(i);
|
|
|
|
found = ban.get(CFBAN_IBAN) == recdoc.get(DOC_IBAN);
|
|
}
|
|
if (!found)
|
|
{
|
|
TRectype recban = vs_ban.key();
|
|
|
|
recban.put(CFBAN_ABI, recdoc.get(DOC_CODABIA));
|
|
recban.put(CFBAN_CAB, recdoc.get(DOC_CODCABA));
|
|
recban.put(CFBAN_NUMCC, recdoc.get(DOC_IBAN).smid(14));
|
|
recban.put(CFBAN_IBAN, recdoc.get(DOC_IBAN));
|
|
vs_ban.add_row(recban);
|
|
vs_ban.write(true);
|
|
}
|
|
}
|
|
|
|
TString abip = recdoc.get(DOC_CODABIP);
|
|
|
|
if (abip.full())
|
|
{
|
|
TToken_string key;
|
|
bool found = false;
|
|
|
|
key.add(tipo);
|
|
key.add(codcf);
|
|
key.add(tipo == "C" ? "V" : "N");
|
|
TRecord_array ns_ban(key, LF_CFBAN);
|
|
const int nsrow = ns_ban.rows();
|
|
|
|
for (int i = 1; !found && i < nsrow; i++)
|
|
{
|
|
TRectype & ban = (TRectype &) ns_ban.row(i);
|
|
|
|
found = ban.get(CFBAN_ABI) == recdoc.get(DOC_CODABIP) &&
|
|
ban.get(CFBAN_CAB) == recdoc.get(DOC_CODCABP) &&
|
|
ban.get(CFBAN_PROGPR) == recdoc.get(DOC_PROGBNP);
|
|
}
|
|
if (!found)
|
|
{
|
|
TRectype recban = ns_ban.key();
|
|
|
|
recban.put(CFBAN_ABI, recdoc.get(DOC_CODABIP));
|
|
recban.put(CFBAN_CAB, recdoc.get(DOC_CODCABP));
|
|
recban.put(CFBAN_PROGPR, recdoc.get(DOC_PROGBNP));
|
|
key = recdoc.get(DOC_CODABIP);
|
|
key << recdoc.get(DOC_CODCABP) << recdoc.get(DOC_PROGBNP);
|
|
|
|
const TRectype & banp = cache().get("BNP", key);
|
|
|
|
recban.put(CFBAN_NUMCC, banp.get("S3").smid(14));
|
|
recban.put(CFBAN_IBAN, banp.get("S3"));
|
|
ns_ban.add_row(recban);
|
|
ns_ban.write(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TOccasionali_mask::occ2clifor(const char * tipo)
|
|
{
|
|
TToken_string key = tipo;
|
|
bool italian = get(O_STATOPAIV).blank();
|
|
bool found = false;
|
|
long codcf = 0L;
|
|
TString8 para;
|
|
TString ragsoc;
|
|
|
|
if (get(O_PAIV).full())
|
|
{
|
|
key.add(get(O_STATOPAIV));
|
|
key.add(get(O_PAIV));
|
|
|
|
const TRectype & clifor = cache().get(LF_CLIFO, key, 5);
|
|
|
|
ragsoc = clifor.get(CLI_RAGSOC);
|
|
codcf = clifor.get_long(CLI_CODCF);
|
|
found = clifor.full();
|
|
if (italian && !found)
|
|
{
|
|
key.add("IT", 1);
|
|
const TRectype & clifor = cache().get(LF_CLIFO, key, 5);
|
|
|
|
found = clifor.full();
|
|
ragsoc = clifor.get(CLI_RAGSOC);
|
|
codcf = clifor.get_long(CLI_CODCF);
|
|
}
|
|
if (found)
|
|
{
|
|
TString message = tipo == "C" ? TR("Il cliente ") : TR("Il fornitore "); message << ragsoc << TR(" ha la stessa partita IVA, devo uilizzarlo");
|
|
|
|
found = yesno_box(message);
|
|
}
|
|
}
|
|
if (!found && get(O_COFI).full())
|
|
{
|
|
key = tipo;
|
|
key.add(get(O_COFI));
|
|
|
|
const TRectype & clifor = cache().get(LF_CLIFO, key, 4);
|
|
|
|
found = clifor.full();
|
|
codcf = clifor.get_long(CLI_CODCF);
|
|
ragsoc = clifor.get(CLI_RAGSOC);
|
|
if (found)
|
|
{
|
|
TString message = tipo == "C" ? TR("Il cliente ") : TR("Il fornitore "); message << ragsoc << TR(" ha lo stesso codice fiscale, devo utilizzarlo");
|
|
|
|
found = yesno_box(message);
|
|
}
|
|
}
|
|
if (!found)
|
|
{
|
|
TFilename tmp;
|
|
|
|
tmp.temp("occ", "ini");
|
|
|
|
{
|
|
TConfig ini(tmp, "Transaction");
|
|
ini.set("Firm", main_app().get_firm());
|
|
ini.set("User", user());
|
|
ini.set("HostName", get_hostname());
|
|
|
|
int year, release, tag, patch;
|
|
if (main_app().get_version_info(year, release, tag, patch))
|
|
{
|
|
TString80 ver;
|
|
ver.format("%d %d.%d-%d", year, release, tag, patch);
|
|
ini.set("Version", ver);
|
|
}
|
|
char mode[2] = { transaction_mode_automatic, '\0' };
|
|
|
|
ini.set("Action", TRANSACTION_INSERT);
|
|
ini.set("Mode", mode);
|
|
para.format("%d", LF_CLIFO);
|
|
ini.set(CLI_RAGSOC, get(O_RAGSOC), para);
|
|
ini.set(CLI_STATOCF, get(O_STATO));
|
|
ini.set(CLI_COMCF, get(O_COMUNE));
|
|
ini.set(CLI_CAPCF, get(O_CAP));
|
|
ini.set(CLI_INDCF, get(O_INDIRIZZO));
|
|
ini.set(CLI_CIVCF, get(O_NUMERO));
|
|
ini.set(CLI_COFI, get(O_COFI));
|
|
ini.set(CLI_STATOPAIV, get(O_STATOPAIV));
|
|
ini.set(CLI_PAIV, get(O_PAIV));
|
|
ini.set(CLI_SESSO, get(O_SESSO));
|
|
ini.set(CLI_DATANASC, get(O_DATANAS));
|
|
ini.set(CLI_STATONASC, get(O_STATONAS));
|
|
ini.set(CLI_COMNASC, get(O_COMUNENAS));
|
|
ini.set(CLI_LOCCF, get(O_LOCALITA));
|
|
ini.set(CLI_REFERENTE, get(O_REFERENTE));
|
|
ini.set(CLI_BYMAIL, get(O_BYMAIL));
|
|
ini.set(CLI_MAIL, get(O_MAIL));
|
|
ini.set(CLI_DOCMAIL, get(O_DOCMAIL));
|
|
ini.set(CLI_PEC, get(O_PEC));
|
|
ini.set(CLI_PTEL, get(O_PTEL));
|
|
ini.set(CLI_TEL, get(O_TEL));
|
|
ini.set(CLI_PTEL2, get(O_PTEL2));
|
|
ini.set(CLI_TEL2, get(O_TEL2));
|
|
ini.set(CLI_PTEL3, get(O_PTEL3));
|
|
ini.set(CLI_TEL3, get(O_TEL3));
|
|
ini.set(CLI_TIPOPERS, get(O_TIPOPERS));
|
|
ini.set(CLI_ALLEG, get(O_ALLEG));
|
|
ini.set(CLI_PFAX, get(O_PFAX));
|
|
ini.set(CLI_FAX, get(O_FAX));
|
|
para.format("%d", LF_CFVEN);
|
|
ini.set(CFV_PADESTIN, get(O_PADESTIN), para);
|
|
}
|
|
|
|
TString cmd("cg0 -1 -i"); cmd << tmp;
|
|
TExternal_app app(cmd);
|
|
|
|
app.run();
|
|
para.format("%d", LF_CLIFO);
|
|
|
|
TConfig ini(tmp, para);
|
|
|
|
codcf = ini.get_long(CLI_CODCF);
|
|
tmp.fremove();
|
|
}
|
|
if (codcf > 0L)
|
|
{
|
|
TMask m("cg0700b");
|
|
TDate from = today;
|
|
|
|
m.set(F_CODICE, get(O_CODICE));
|
|
m.set(F_CODCF, codcf);
|
|
m.set(F_RAGSOC, ragsoc);
|
|
from.set_start_year();
|
|
m.set(F_FROM, from);
|
|
if (m.run() == K_ENTER)
|
|
{
|
|
TString query("USE ");
|
|
|
|
query << LF_DOC << " SELECT " << DOC_OCFPI << "==\"" << get(O_CODICE) << "\"\n";
|
|
query << "FROM " << DOC_ANNO << "=" << from.year();
|
|
|
|
TISAM_recordset clifor_recset(query);
|
|
const int items = clifor_recset.items();
|
|
|
|
clifor_recset.freeze();
|
|
if (items == 0)
|
|
message_box(TR("Nessun documento trovato"));
|
|
else
|
|
{
|
|
TProgress_monitor p(items, "Aggiornamento documenti");
|
|
const TRectype & recdoc = clifor_recset.curr();
|
|
|
|
for (clifor_recset.move_first(); p.addstatus() && !clifor_recset.eof(); clifor_recset.move_next())
|
|
{
|
|
TDocumento doc(recdoc);
|
|
|
|
doc.put(DOC_CODCF, codcf);
|
|
doc.zero(DOC_OCFPI);
|
|
doc.zero(DOC_OCCAS);
|
|
doc.rewrite();
|
|
}
|
|
key = tipo;
|
|
key.add(codcf);
|
|
TRectype & clifor = (TRectype &) cache().get(LF_CLIFO, key);
|
|
|
|
clifor_recset.move_last();
|
|
clifor.put(CLI_CODVAL, recdoc.get(DOC_CODVAL));
|
|
clifor.put(CLI_CODLIN, recdoc.get(DOC_CODLIN));
|
|
clifor.put(CLI_CODPAG, recdoc.get(DOC_CODPAG));
|
|
clifor.rewrite();
|
|
update_ban(tipo, codcf, recdoc);
|
|
|
|
TRectype & cfven = (TRectype &)cache().get(LF_CFVEN, key);
|
|
|
|
cfven.put(CFV_CATVEN, recdoc.get(DOC_CATVEN));
|
|
cfven.put(CFV_CODLIST, recdoc.get(DOC_CODLIST));
|
|
cfven.put(CFV_CODZONA, recdoc.get(DOC_ZONA));
|
|
cfven.put(CFV_CODAG, recdoc.get(DOC_CODAG));
|
|
cfven.put(CFV_CODAG1, recdoc.get(DOC_CODAGVIS));
|
|
cfven.put(CFV_CODSPMEZZO, recdoc.get(DOC_CODSPMEZZO));
|
|
cfven.put(CFV_CODPORTO, recdoc.get(DOC_CODPORTO));
|
|
cfven.put(CFV_CODVETT1, recdoc.get(DOC_CODVETT1));
|
|
cfven.put(CFV_CODVETT2, recdoc.get(DOC_CODVETT2));
|
|
cfven.put(CFV_CODVETT3, recdoc.get(DOC_CODVETT3));
|
|
cfven.write_rewrite();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TOccasionali_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case O_COFI:
|
|
if (e == fe_modify)
|
|
{
|
|
TMask& m = o.mask();
|
|
TString16 cofi = m.get(O_COFI);
|
|
|
|
if (cofi.blank())
|
|
cofi = m.get(O_CODICE);
|
|
if (cf_check(m.get(O_STATONAS), cofi))
|
|
{
|
|
int giorno = atoi(cofi.smid(9,2));
|
|
m.set(O_SESSO, giorno > 40 ? "F" : "M");
|
|
|
|
if (m.field(O_COMUNENAS).empty())
|
|
m.set(O_COMUNENAS, cofi.smid(11,4), 0x2);
|
|
|
|
if (m.field(O_DATANAS).empty())
|
|
{
|
|
const TFixed_string mesi("ABCDEHLMPRST");
|
|
const int mese = mesi.find(cofi[8])+1;
|
|
int anno = atoi(cofi.smid(6,2));
|
|
|
|
if (giorno > 0 && mese > 0 && anno > 0)
|
|
{
|
|
giorno %= 40;
|
|
anno += anno < 5 ? 2000 : 1900;
|
|
m.set(O_DATANAS, TDate(giorno, mese, anno));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case DLG_CLI:
|
|
if (e == fe_button)
|
|
occ2clifor("C");
|
|
break;
|
|
case DLG_FOR:
|
|
if (e == fe_button)
|
|
occ2clifor("F");
|
|
break;
|
|
default: break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
class TOccasionali_app : public TRelation_application
|
|
{
|
|
TOccasionali_mask * _msk;
|
|
TRelation * _rel;
|
|
|
|
bool user_create();
|
|
bool user_destroy();
|
|
virtual void init_query_mode(TMask&) override;
|
|
// @cmember Inizializza la maschera per il modo inserimento
|
|
virtual void init_insert_mode(TMask&) override;
|
|
// @cmember Inizializza la maschera per il modo modifica
|
|
virtual void init_modify_mode(TMask&) override;
|
|
virtual TMask* _get_mask(int mode) {return _msk;}
|
|
virtual bool changing_mask(int mode) {return false;}
|
|
void ini2mask(TConfig& ini, TMask& m, bool query);
|
|
|
|
public:
|
|
// @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata
|
|
virtual bool check_autorization() const { return false; }
|
|
virtual TRelation* get_relation() const {return _rel;}
|
|
};
|
|
|
|
HIDDEN inline TOccasionali_app& app() { return (TOccasionali_app&) main_app();}
|
|
|
|
void TOccasionali_app::init_query_mode(TMask& m)
|
|
{
|
|
m.disable(DLG_CLI);
|
|
m.disable(DLG_FOR);
|
|
TRelation_application::init_query_mode(m);
|
|
}
|
|
|
|
void TOccasionali_app::init_insert_mode(TMask& m)
|
|
{
|
|
m.disable(DLG_CLI);
|
|
m.disable(DLG_FOR);
|
|
}
|
|
|
|
void TOccasionali_app::init_modify_mode(TMask& m)
|
|
{
|
|
m.enable(DLG_CLI);
|
|
m.enable(DLG_FOR);
|
|
}
|
|
|
|
bool TOccasionali_app::user_create()
|
|
{
|
|
open_files(LF_OCCAS, LF_CLIFO, LF_CFVEN, LF_DOC, LF_RIGHEDOC, LF_CFBAN, 0);
|
|
_rel = new TRelation(LF_OCCAS);
|
|
_msk = new TOccasionali_mask() ;
|
|
return true;
|
|
}
|
|
|
|
bool TOccasionali_app::user_destroy()
|
|
{
|
|
safe_delete(_rel);
|
|
safe_delete(_msk);
|
|
return true;
|
|
}
|
|
|
|
void TOccasionali_app::ini2mask(TConfig& ini, TMask& m, bool query)
|
|
{
|
|
TString istat = ini.get_int(COM_CODISTAT);
|
|
|
|
if (istat.full())
|
|
{
|
|
const TRectype & com = cache().get(LF_COMUNI, istat);
|
|
|
|
ini.set(OCC_STATO, com.get(COM_STATO));
|
|
ini.set(OCC_COM, com.get(COM_COM));
|
|
}
|
|
|
|
istat = ini.get_int("CODISTATNASC");
|
|
|
|
if (istat.full())
|
|
{
|
|
const TRectype & com = cache().get(LF_COMUNI, istat);
|
|
|
|
ini.set(OCC_STATONASC, com.get(COM_STATO));
|
|
ini.set(OCC_COMNASC, com.get(COM_COM));
|
|
}
|
|
|
|
TRelation_application::ini2mask(ini, m, query);
|
|
}
|
|
|
|
|
|
int cg0700(int argc, char* argv[])
|
|
{
|
|
TOccasionali_app a ;
|
|
a.run(argc, argv, TR("Clienti/Fornitori Occasionali"));
|
|
return 0;
|
|
}
|