Esportazione rilevazione ore a paghe

git-svn-id: svn://10.65.10.50/branches/R_10_00@23073 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2015-04-30 09:42:59 +00:00
parent 9f33a265d6
commit c3d63f12b2
6 changed files with 1428 additions and 0 deletions

186
ci/ci1500.cpp Normal file
View File

@ -0,0 +1,186 @@
#include <applicat.h>
#include "../ve/velib04.h"
#include "ci1.h"
///////////////////////////////////////////////////////////
// Applicazione
///////////////////////////////////////////////////////////
class TMovimenti_interni_app : public TSkeleton_application
{
TFilename _trans;
protected:
TDoc_key find_correlated(const TDocumento& din) const;
void delete_doc(TDocumento& doc) const;
public:
virtual bool create();
virtual void main_loop();
};
TDoc_key TMovimenti_interni_app::find_correlated(const TDocumento& din) const
{
TDoc_key dk;
TString query, filter;
filter << ' ' << RDOC_DAPROVV << '=' << din.get(DOC_PROVV)
<< ' ' << RDOC_DAANNO << '=' << din.get(DOC_ANNO)
<< ' ' << RDOC_DACODNUM << '=' << din.get(DOC_CODNUM)
<< ' ' << RDOC_DANDOC << '=' << din.get(DOC_NDOC);
query << "USE 34 KEY 4" << "\nFROM " << filter << "\nTO " << filter;
TISAM_recordset rset(query);
if (rset.move_first())
{
const char provv = rset.get(RDOC_PROVV).as_string()[0];
const int anno = rset.get(RDOC_ANNO).as_int();
const TString4 codnum = rset.get(RDOC_CODNUM).as_string();
const long ndoc = rset.get(RDOC_NDOC).as_int();
dk = TDoc_key(anno, codnum, ndoc, provv);
}
return dk;
}
void TMovimenti_interni_app::delete_doc(TDocumento& doc) const
{
doc.remove();
}
bool TMovimenti_interni_app::create()
{
const TFixed_string a2 = argc() >= 2 ? argv(2) : "";
if (a2.starts_with("-i", true) || a2.starts_with("/i", true))
_trans = a2.mid(2);
#ifdef DBG
if (_trans.blank())
{
const TDate oggi(TODAY);
_trans.tempdir();
_trans.add(name());
_trans.ext("ini");
TConfig ini(_trans, "Transaction");
ini.set("DataElab", oggi.string());
ini.set("ProvvOut", "D");
ini.set("AnnoOut", 2014);
ini.set("CodNumOut", "TRAS");
ini.set("NDocOut", "");
ini.set_paragraph("33");
ini.set(DOC_PROVV, "D");
ini.set(DOC_ANNO, 2014);
ini.set(DOC_CODNUM, "TRAS");
ini.set(DOC_NDOC, 1);
}
#endif
if (!_trans.exist())
return cantread_box(_trans);
open_files(LF_TABCOM, LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_CODCORR, 0);
return TSkeleton_application::create();
}
void TMovimenti_interni_app::main_loop()
{
TConfig ini(_trans, "Transaction");
const TString8 codelab = ini.get("Action");
const TDate oggi = ini.get("DataElab");
ini.set_paragraph("33");
const char provv = ini.get_char(DOC_PROVV);
const int anno = ini.get_int(DOC_ANNO);
const TString& codnum = ini.get(DOC_CODNUM);
const long ndoc = ini.get_long(DOC_NDOC);
TElaborazione_esterna mi(codelab);
const TString4 tipo_correlato = mi.tipo_finale();
TDocumento din(provv, anno, codnum, ndoc);
TDoc_key kout = find_correlated(din);
const bool is_new = kout.empty_items();
if (is_new)
kout = TDoc_key(anno, codnum, 0, provv);
TDocumento dout(kout.provv(), kout.anno(), kout.codnum(), kout.ndoc());
if (ini.get(DOC_NOTE) == "DELETING")
{
delete_doc(dout);
ini.set("Result", "SUCCESS");
return;
}
dout.copy_contents(din, true);
dout.put(DOC_TIPODOC, tipo_correlato);
dout.put(DOC_CODCMS, din.get(DOC_COMMPREL));
dout.put(DOC_FASCMS, din.get(DOC_FASEPREL));
dout.put(DOC_COMMPREL, din.get(DOC_CODCMS));
dout.put(DOC_FASEPREL, din.get(DOC_FASCMS));
const TString16 qtafld = din.tipo().field_qta();
FOR_EACH_PHYSICAL_RDOC(dout, r, rdoc)
{
const real qta = rdoc->get_real(qtafld);
if (!qta.is_zero())
rdoc->put(qtafld, -qta);
rdoc->put(RDOC_CODCMS, dout.get(DOC_CODCMS));
rdoc->put(RDOC_FASCMS, dout.get(DOC_FASCMS));
}
ini.set_paragraph("Transaction");
if (dout.write(!is_new) == NOERR)
{
ini.set("Result", "OUTDOC");
ini.set("NDocOut", dout.get(DOC_NDOC));
ini.set(DOC_STATO, mi.stato_finale_doc_iniziale(), "33");
}
else
{
ini.set("Result", "ERROR");
}
if (ca_config().get_int("Authorizations") > 0)
{
TString8 codelab;
TString query;
query << "USE %ELD SELECT I0=7";
TISAM_recordset eld(query);
for (bool ok = eld.move_first(); ok; ok = eld.move_next())
{
const TString8 cod = eld.get("CODTAB").as_string();
if (codelab.blank())
codelab = cod;
TContabilizzazione_analitica ca(cod);
if (ca.is_document_ok(dout))
{
codelab = cod;
break;
}
}
TContabilizzazione_analitica ca(codelab);
TLista_documenti lista_in, lista_out;
lista_in.add(din);
lista_in.add(dout);
if (ca.elabora(lista_in, lista_out, oggi, false))
{
// Forza stato corretto a documento principale
din.put(DOC_STATO, mi.stato_finale_doc_iniziale());
din.rewrite();
// Forza stato bloccato a documento correlato
dout.put(DOC_STATO, mi.stato_finale());
dout.rewrite();
}
}
}
int ci1500(int argc, char* argv[])
{
TMovimenti_interni_app mi;
mi.run(argc, argv, TR("Movimenti interni"));
return 0;
}

299
ci/ci1600.cpp Normal file
View File

@ -0,0 +1,299 @@
#include <applicat.h>
#include <automask.h>
#include "../ve/velib.h"
#include "ci1.h"
#include "ci1600a.h"
///////////////////////////////////////////////////////////
// Utilities
///////////////////////////////////////////////////////////
static bool in_movint_filter(const TRectype& rdoc)
{
static TAssoc_array movint_num;
if (rdoc.get_real(RDOC_QTA).is_zero() || rdoc.get(RDOC_CODARTMAG).empty())
return false; // not an article
const TString4 codnum = rdoc.get(RDOC_CODNUM);
if (!movint_num.is_key(codnum))
{
TLocalisamfile doc(LF_DOC);
doc.put(DOC_PROVV, rdoc.get(RDOC_PROVV));
doc.put(DOC_ANNO, rdoc.get(RDOC_ANNO));
doc.put(DOC_CODNUM, rdoc.get(RDOC_CODNUM));
doc.put(DOC_NDOC, rdoc.get(RDOC_NDOC));
doc.read();
real sg = ZERO;
const TTipo_documento& tipo = cached_tipodoc(doc.get(DOC_TIPODOC));
if (tipo.is_bolla())
{
const TString& causmag = tipo.caus_mov();
if (causmag.full())
{
const TCausale_magazzino caus(causmag);
sg = caus.sgn(s_giac);
}
}
movint_num.add(codnum, sg);
}
const real sg = *(real*)movint_num.objptr(codnum);
return !sg.is_zero();
}
///////////////////////////////////////////////////////////
// Maschera
///////////////////////////////////////////////////////////
class TInterrogazione_msk : public TAutomask
{
protected:
void fill_sheet();
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TInterrogazione_msk(const TDocumento& din);
};
void TInterrogazione_msk::fill_sheet()
{
const TString& cms = get(F_CODCMS);
const TString& art = get(F_CODART);
const bool null_giac = get_bool(F_NULLGIAC);
TString query;
query << "USE " << LF_RIGHEDOC << " KEY 6 SELECT CODARTMAG!=\"\""
<< "\nFROM " << RDOC_CODCMS << '=' << cms
<< "\nTO " << RDOC_CODCMS << '=' << cms;
TAssoc_array saldi;
TISAM_recordset rdoc_set(query);
const TRectype& rdoc = rdoc_set.cursor()->curr();
for (bool ok = rdoc_set.move_first(); ok; ok = rdoc_set.move_next())
{
if (!in_movint_filter(rdoc))
continue;
const TString& codart = rdoc.get(RDOC_CODARTMAG);
if (art.full() && !codart.starts_with(art, true))
continue;
const real qta = rdoc.get_real(RDOC_QTA);
real* s = (real*)saldi.objptr(codart);
if (s == NULL)
saldi.add(codart, qta);
else
*s += qta;
}
const TDate oggi(TODAY);
TEsercizi_contabili esc;
const int annoes = esc.date2esc(oggi);
TSheet_field& sheet = sfield(F_RIGHE);
sheet.hide();
sheet.destroy();
FOR_EACH_ASSOC_OBJECT(saldi, hash, key, itm)
{
const real& giac = *(real*)itm;
if (!null_giac && giac <= ZERO)
continue;
const TArticolo_giacenza& art = cached_article_balances(key);
TToken_string& row = sheet.row(-1);
row.add(art.um()[1].get(UMART_UM), 2);
row.add(giac.string(0, 2));
row.add(key);
row.add(art.descrizione());
row.add(art.get(ANAMAG_CODIVA));
row.add(art.costo_medio(annoes, "", "").string(0,2));
row.add(art.scorta_minima("", "", annoes).string(0,2));
}
sheet.force_update();
sheet.show();
}
bool TInterrogazione_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_CODART:
case F_NULLGIAC:
if (e == fe_modify)
fill_sheet();
break;
case F_RIGHE:
if (e == se_query_del)
return false;
if (e == se_query_add)
fill_sheet();
break;
case S_CHECKED:
if (e == fe_modify)
{
TMask& m = o.mask();
if (o.get().full())
{
if (m.get_real(S_QTA).is_zero())
m.set(S_QTA, m.get(S_SALDO));
}
else
m.reset(S_QTA);
}
break;
case S_QTA:
if (e == fe_modify)
{
const real q = o.get();
o.mask().set(S_CHECKED, !q.is_zero());
}
break;
default:
break;
}
return true;
}
TInterrogazione_msk::TInterrogazione_msk(const TDocumento& din) : TAutomask("ci1600a")
{
set(F_CODCMS, din.get(DOC_COMMPREL), 0x3);
set(F_CODFAS, din.get(DOC_FASEPREL), 0x3);
fill_sheet();
}
///////////////////////////////////////////////////////////
// Applicazione
///////////////////////////////////////////////////////////
class TInterrogazione_app : public TSkeleton_application
{
TFilename _trans;
protected:
public:
virtual bool create();
virtual void main_loop();
};
bool TInterrogazione_app::create()
{
const TFixed_string a2 = argc() >= 2 ? argv(2) : "";
if (a2.starts_with("-i", true) || a2.starts_with("/i", true))
_trans = a2.mid(2);
#ifdef DBG
if (_trans.blank())
{
const TDate oggi(TODAY);
_trans.tempdir();
_trans.add(name());
_trans.ext("ini");
TConfig ini(_trans, "Transaction");
ini.set("DataElab", oggi.string());
ini.set_paragraph("33");
ini.set(DOC_PROVV, "D");
ini.set(DOC_ANNO, 2014);
ini.set(DOC_CODNUM, "TRAS");
ini.set(DOC_NDOC, 1);
}
#endif
if (!_trans.exist())
return cantread_box(_trans);
open_files(LF_TABCOM, LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_CODCORR, 0);
return TSkeleton_application::create();
}
void TInterrogazione_app::main_loop()
{
TConfig ini(_trans, "Transaction");
const TDate oggi = ini.get("DataElab");
ini.set_paragraph("33");
const char provv = ini.get_char(DOC_PROVV);
const int anno = ini.get_int(DOC_ANNO);
const TString& codnum = ini.get(DOC_CODNUM);
const long ndoc = ini.get_long(DOC_NDOC);
TDocumento din(provv, anno, codnum, ndoc);
TString4 riga_merce = "01"; // Stabilisce il tipo riga standard per la merce
FOR_EACH_PHYSICAL_RDOC(din, r, rdoc)
{
if (rdoc->is_merce())
{
riga_merce = rdoc->get(RDOC_TIPORIGA);
break;
}
}
const int last_row = din.rows(); // Ultima riga del documento originale dopo cui fare aggiunte
TInterrogazione_msk m(din);
while (m.run() == K_ENTER)
{
const TSheet_field& sheet = m.sfield(F_RIGHE);
const int iqta = sheet.cid2index(S_QTA);
const int iart = sheet.cid2index(S_CODART);
const int iiva = sheet.cid2index(S_CODIVA);
const int iums = sheet.cid2index(S_UM);
const int ides = sheet.cid2index(S_DESART);
int nr = 0, nu = 0;
FOR_EACH_ARRAY_ROW(sheet.rows_array(), r, riga)
{
const real qta = riga->get(iqta);
if (!qta.is_zero())
{
// Cerca una riga nuova (>last_row) col codice articolo corrispondente
const TCodice_articolo codart = riga->get(iart);
int nriga = 0;
for (nriga = din.rows(); nriga > last_row; nriga--)
if (din[nriga].get(RDOC_CODARTMAG) == codart) break;
if (nriga <= last_row) // Se non la trova, ne crea una nuova
{
TRiga_documento& rdoc = din.new_row(riga_merce);
rdoc.put(RDOC_CODART, codart);
rdoc.put(RDOC_CODARTMAG, codart);
rdoc.put(RDOC_CHECKED, "X");
rdoc.put(RDOC_UMQTA, riga->get(iums));
rdoc.put(RDOC_CODIVA, riga->get(iiva));
rdoc.put(RDOC_DESCR, riga->get(ides));
nriga = rdoc.get_int(RDOC_NRIGA);
nr++;
}
else
nu++;
din[nriga].put(RDOC_QTA, qta);
}
}
message_box(FR("Sono state aggiunte %d righe ed aggiornate %d"), nr, nu);
}
if (din.rows() > last_row) // Sono state fatte aggiunte?
{
TString8 para;
for (int i = din.rows(); i > last_row; i--)
{
const TRiga_documento& rdoc = din[i];
para.format("%d,%d", LF_RIGHEDOC, i);
ini.set_paragraph(para);
for (int f = 0; f < rdoc.items(); f++)
{
const char* fld = rdoc.fieldname(f);
const TString& val = rdoc.get(fld);
if (val.full() && val.len() <= 50)
ini.set(fld, val);
}
}
}
ini.set_paragraph("Transaction");
ini.set("Result", "SUCCESS");
ini.set("Error", "0");
}
int ci1600(int argc, char* argv[])
{
TInterrogazione_app mi;
mi.run(argc, argv, TR("Interrogazione magazzino"));
return 0;
}

18
ci/ci1600a.h Normal file
View File

@ -0,0 +1,18 @@
#define F_CODCMS 201
#define F_DESCMS 202
#define F_CODFAS 203
#define F_DESFAS 204
#define F_CODART 205
#define F_DESART 206
#define F_NULLGIAC 207
#define F_RIGHE 210
#define S_CHECKED 101
#define S_QTA 102
#define S_UM 103
#define S_SALDO 104
#define S_CODART 105
#define S_DESART 106
#define S_CODIVA 107
#define S_COSTO 108
#define S_SCORTA 109

173
ci/ci1600a.uml Normal file
View File

@ -0,0 +1,173 @@
#include "ci1600a.h"
TOOLBAR "topbar" 0 0 0 2
#include <elabar.h>
ENDPAGE
PAGE "Interrogazione magazzino" -1 -1 0 0
GROUPBOX -1 78 4
BEGIN
PROMPT 1 1 "@bCommessa di prelievo"
END
STRING F_CODCMS 20
BEGIN
PROMPT 2 2 "Commessa "
USE LF_COMMESSE
INPUT CODCMS F_CODCMS
DISPLAY "Codice@20" CODCMS
DISPLAY "Descrizione@50" DESCRIZ
OUTPUT F_CODCMS CODCMS
OUTPUT F_DESCMS DESCRIZ
CHECKTYPE NORMAL
FLAGS "D"
END
STRING F_DESCMS 50 42
BEGIN
PROMPT 34 2 ""
FLAGS "D"
END
STRING F_CODFAS 20
BEGIN
PROMPT 2 3 "Fase "
USE LF_FASI
INPUT CODFASE F_CODFAS
DISPLAY "Codice@20" CODFASE
DISPLAY "Descrizione@50" DESCRIZ
OUTPUT F_CODFAS CODCOSTO
OUTPUT F_DESFAS DESCRIZ
CHECKTYPE NORMAL
FLAGS "D"
END
STRING F_DESFAS 50 42
BEGIN
PROMPT 34 3 ""
FLAGS "D"
END
GROUPBOX -1 78 4
BEGIN
PROMPT 1 5 "@bArticolo"
END
STRING F_CODART 20
BEGIN
PROMPT 2 6 "Articolo "
USE LF_ANAMAG
INPUT CODART F_CODART
DISPLAY "Articolo@20" CODART
DISPLAY "Descrizione@50" DESCR
OUTPUT F_CODART CODART
OUTPUT F_DESART DESCR
CHECKTYPE SEARCH
END
STRING F_DESART 50 36
BEGIN
PROMPT 10 7 ""
USE LF_ANAMAG KEY 2
INPUT DESCR F_DESART
DISPLAY "Descrizione@50" DESCR
DISPLAY "Articolo@20" CODART
COPY OUTPUT F_CODART
CHECKTYPE SEARCH
END
BOOLEAN F_NULLGIAC
BEGIN
PROMPT 36 6 "Includere giacenze nulle o negative"
END
SPREADSHEET F_RIGHE 0 0
BEGIN
PROMPT 1 9 ""
ITEM "@1C"
ITEM "Quantità@15V"
ITEM "U.M."
ITEM "Saldo@15V"
ITEM "Articolo@20"
ITEM "Descrizione@50"
ITEM "IVA@4"
ITEM "Costo Medio@15V"
ITEM "Scorta minima@15V"
END
ENDPAGE
ENDMASK
PAGE "Articolo" -1 -1 78 5
BOOLEAN S_CHECKED
BEGIN
PROMPT 1 1 "Selezione "
END
NUMBER S_QTA 15 2
BEGIN
PROMPT 16 1 "Quantità "
END
STRING S_UM 2
BEGIN
PROMPT 40 1 "U.M. "
FLAGS "L"
END
NUMBER S_SALDO 15 2
BEGIN
PROMPT 50 1 "Giacenza "
FLAGS "L"
END
STRING S_CODART 20
BEGIN
PROMPT 1 2 "Articolo "
FLAGS "L"
END
STRING S_DESART 50
BEGIN
PROMPT 1 3 "Descrizione "
FLAGS "L"
END
STRING S_CODIVA 4
BEGIN
PROMPT 26 1 "IVA "
FLAGS "L"
END
CURRENCY S_COSTO 15
BEGIN
PROMPT 1 4 "Costo "
FLAGS "L"
END
NUMBER S_SCORTA 15 2
BEGIN
PROMPT 36 4 "Scorta minima "
FLAGS "L"
END
ENDPAGE
TOOLBAR "topbar" 0 0 0 2
BUTTON DLG_OK 2 2
BEGIN
PROMPT 1 1 ""
END
BUTTON DLG_CANCEL 2 2
BEGIN
PROMPT 3 1 ""
END
ENDPAGE
ENDMASK

746
ci/ci2401.cpp Normal file
View File

@ -0,0 +1,746 @@
#include "ci2401.h"
#include <automask.h>
#include <colors.h>
#include <diction.h>
#include <golem.h>
#include <progind.h>
#include <recarray.h>
#include <relation.h>
#include <reputils.h>
#include <textset.h>
#include <toolfld.h>
#include <urldefid.h>
#include "ci2400a.h"
////////////////////////////////////////////////////////////////////////////
// Recordset per paghe Zucchetti
////////////////////////////////////////////////////////////////////////////
class TRP_set : public TAS400_recordset
{
public:
bool find_or_create(const TString& risorsa);
bool load(const TFilename& filename);
bool find(const long matricola);
TRP_set(int ditta, int filiale);
};
bool TRP_set::find(const long mat)
{
if (mat > 0)
{
for (bool good = move_first(); good; good = move_next())
if (get("MATRICOLA").as_int() == mat)
return true;
}
return false;
}
bool TRP_set::find_or_create(const TString& risorsa)
{
const TRectype& rss = cache().get("RSS", risorsa);
const long num_mat = atol(rss.get("S3").mid(4, 6));
bool found = false;
if (num_mat > 0)
{
found = find(num_mat);
if (!found)
{
new_rec("");
found = move_last();
set("MATRICOLA", num_mat);
TString80 descr = rss.get("S0"); descr.strip_double_spaces();
const int spc = descr.find(' ');
if (spc > 0)
{
set("COGNOME", descr.left(min(spc, 34)));
set("NOME", descr.mid(spc+1, 34));
}
else
set("COGNOME", descr);
}
}
return found;
}
bool TRP_set::load(const TFilename& filename)
{
bool done = load_file(filename);
if (done)
_query = filename;
return done;
}
TRP_set::TRP_set(int ditta, int filiale) : TAS400_recordset("AS400(1707)")
{
create_field("DITTA" , 0, 4, _intzerofld, true, (long)ditta);
create_field("FILIALE", -1, 2, _intzerofld, true, (long)filiale);
create_field("SIGLA", -1, 3, _alfafld, true, "RP ");
create_field("MATRICOLA", -1, 6, _longzerofld, true);
create_field("COGNOME", -1, 34, _alfafld, true);
create_field("NOME", -1, 34, _alfafld, true);
create_field("DATAINI", -1, 6, _longfld, true);
create_field("DATAFIN", -1, 6, _longfld, true);
TString16 fld;
for (int gg = 1; gg <= 31; gg++)
{
fld.format("ORE_ORDIN_%02d", gg);
create_field(fld, -1, 4, _intzerofld);
for (int i = 1; i <= 6; i++)
{
fld.format("SIGLA_PRES%d_%02d", i, gg);
create_field(fld, -1, 2, _alfafld);
fld.format("SOMMA_ORDIN%d_%02d", i, gg);
create_field(fld, -1, 1, _alfafld);
fld.format("STAMPA_MESS%d_%02d", i, gg);
create_field(fld, -1, 1, _alfafld);
fld.format("ORE_GIUST%d_%02d", i, gg);
create_field(fld, -1, 4, _intzerofld);
}
}
}
////////////////////////////////////////////////////////////////////////////
// Recordset per Excel
////////////////////////////////////////////////////////////////////////////
class TRP_xlset : public TCSV_recordset
{
public:
TRP_xlset(TRP_set& rp);
};
static int rp_cmp(const TObject** o1, const TObject** o2)
{
TToken_string& s1 = *(TToken_string*)*o1;
TToken_string& s2 = *(TToken_string*)*o2;
return s1.get_long(0) - s2.get_long(0);
}
TRP_xlset::TRP_xlset(TRP_set& rp) : TCSV_recordset("")
{
create_column("MATRICOLA", _intfld);
create_column("COGNOME", _alfafld);
create_column("NOME", _alfafld);
create_column("Totale", _realfld);
create_column("Ordinarie", _realfld);
for (bool ok = rp.move_first(); ok; ok = rp.move_next())
{
TToken_string data(127, separator());
for (int i = 0; i < 3; i++)
{
const char* name = column_info(i)._name;
data.add(rp.get(name).as_string());
}
TString16 fld;
for (int gg = 1; gg <= 31; gg++)
{
fld.format("ORE_ORDIN_%02d", gg);
real ord = rp.get(fld).as_real();
if (!ord.is_zero())
{
ord /= CENTO;
real tot = data.get(4);
tot += ord;
data.add(tot.string(), 4);
}
for (int i = 1; i <= 6; i++)
{
fld.format("SIGLA_PRES%d_%02d", i, gg);
const TString4 sigla = rp.get(fld).as_string();
if (sigla.blank())
break;
unsigned int col = 0;
for (col = columns()-1; col > 4; col--)
{
if (column_info(col)._name == sigla)
break;
}
if (col <= 4)
{
create_column(sigla, _realfld);
col = columns()-1;
}
fld.format("ORE_GIUST%d_%02d", i, gg);
const real qta = rp.get(fld).as_real();
if (!qta.is_zero())
{
real ore = data.get(col);
ore += qta / CENTO;
data.add(ore.string(), col);
}
}
}
real tot;
for (unsigned col = columns()-1; col > 3; col--)
tot += real(data.get(col));
data.add(tot.string(), 3);
new_rec(data);
}
sort(rp_cmp);
}
////////////////////////////////////////////////////////////////////////////
// Maschera edit
////////////////////////////////////////////////////////////////////////////
class TEdit_mask : public TAutomask
{
TRP_set& _ps;
TString_array _tipi;
bool _ris_dirty;
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
bool save_if_dirty_ris();
void load_ris();
bool save_ris();
void select_ris(bool by_name);
public:
TEdit_mask(TRP_set& ps);
};
inline bool is_red_day(const TDate& d)
{ return d.wday() >= 6 || d.is_holiday(); }
void TEdit_mask::load_ris()
{
const long dataini = _ps.get("DATAINI").as_int(); // 010115
const long datafin = _ps.get("DATAFIN").as_int(); // 310115
const int anno = 2000 + dataini % 100;
const int mese = dataini / 100 % 100;
set(F_ANNO, anno);
set(F_MESE, mese);
set(F_CODRIS, _ps.get("MATRICOLA").as_int());
set(F_DESRIS, _ps.get("COGNOME").as_string());
TSheet_field& s = sfield(F_SHEET);
short tot_id = 102;
const TMask& sm = s.sheet_mask();
for (tot_id = 108; sm.id2pos(tot_id) > 0; tot_id++);
tot_id --;
s.hide();
s.destroy();
TToken_string row;
TString16 fld;
const int ug = datafin/10000; // Ultimo giorno
for (int gg = 1; gg <= ug; gg++)
{
fld.format("ORE_ORDIN_%02d", gg);
real totale = _ps.get(fld).as_int();
if (!totale.is_zero())
{
totale /= CENTO;
row = totale.string();
}
else
row.cut(0);
for (int i = 1; i <= 6; i++)
{
fld.format("SIGLA_PRES%d_%02d", i, gg);
const TString& tipo = _ps.get(fld).as_string();
if (tipo.full())
{
const int idx = _tipi.find(tipo);
if (idx >= 0 && short(102+idx) < tot_id)
{
fld.format("ORE_GIUST%d_%02d", i, gg);
real ore = _ps.get(fld).as_int();
if (!ore.is_zero())
{
ore /= CENTO;
row.add(ore.string(), idx+1);
totale += ore;
}
}
}
}
if (!totale.is_zero())
row.add(totale.string(), s.cid2index(tot_id));
s.rows_array().add(row);
const TDate d(gg, mese, anno);
if (is_red_day(d))
s.set_back_and_fore_color(REQUIRED_BACK_COLOR, NORMAL_COLOR, gg-1);
else
{
TDate ieri = d; --ieri;
TDate domani = d; ++domani;
if (is_red_day(ieri) && is_red_day(domani))
s.set_back_and_fore_color(EASY_RIDER_COLOR, NORMAL_COLOR, gg-1);
}
}
s.force_update();
s.show();
enable(DLG_SAVEREC, _ris_dirty = false);
}
void TEdit_mask::select_ris(bool by_name)
{
if (save_if_dirty_ris())
{
const long cur_mat = get_long(F_CODRIS);
const char* header = by_name ? HR("Cognome@34|Nome@34|Matricola@8R") : HR("Matricola@8R|Cognome@34|Nome@34");
TArray_sheet a(-1, 3, 0, -3, TR("Selezione risorse"), header);
for (bool good = _ps.move_first(); good; good = _ps.move_next())
{
TToken_string row;
TString8 zmat; zmat.format("%06ld", _ps.get("MATRICOLA").as_int());
if (!by_name)
row.add(zmat);
row.add(_ps.get("COGNOME").as_string());
row.add(_ps.get("NOME").as_string());
if (by_name)
row.add(zmat);
a.add(row);
}
a.rows_array().sort();
for (int i = a.items()-1; i >= 0; i--)
{
const long mat = a.row(i).get_long(by_name ? 2 : 0);
if (mat == cur_mat)
{
a.select(i);
break;
}
}
if (a.run() == K_ENTER)
{
TToken_string& row = a.row(a.selected());
const long matricola = row.get_long(by_name ? 2 : 0);
if (_ps.find(matricola))
load_ris();
}
}
}
bool TEdit_mask::save_ris()
{
const long matricola = get_long(F_CODRIS);
if (!_ps.find(matricola))
{
TString msg;
msg << TR("Matricola sconosciuta ") << matricola;
return cantread_box(msg);
}
ini_set_int(CONFIG_DITTA, "ci", "RILPRE_RIS", matricola);
TSheet_field& s = sfield(F_SHEET);
short last_id = 102;
const TMask& sm = s.sheet_mask();
for (last_id = 108; sm.id2pos(last_id) > 0; last_id++);
last_id -= 2; // Identificatore dell'ultimo tipo ora
TString16 fld;
real ore;
FOR_EACH_SHEET_ROW(s, r, row)
{
const int gg = r+1;
row->get(0, ore);
ore *= CENTO;
fld.format("ORE_ORDIN_%02d", gg);
_ps.set(fld, ore.integer());
// Azzera straordinari preesistenti
int og = 1;
for (og = 1; og <= 6; og++)
{
fld.format("SIGLA_PRES%d_%02d", og, gg);
_ps.set(fld, EMPTY_STRING);
fld.format("ORE_GIUST%d_%02d", og, gg);
_ps.set(fld, 0L);
}
og = 1;
for (int i = 0; i < _tipi.items() && og <= 6; i++)
{
const short id = 102+i;
if (id > last_id)
break;
row->get(i+1, ore);
if (!ore.is_zero())
{
ore *= CENTO;
const TString& tipo_ora = _tipi.row(i);
fld.format("SIGLA_PRES%d_%02d", og, gg);
_ps.set(fld, tipo_ora);
fld.format("ORE_GIUST%d_%02d", og, gg);
_ps.set(fld, ore.integer());
og++;
}
}
}
const TFilename fn = _ps.query_text();
bool done = fn.exist() && _ps.save_as(fn);
if (done)
enable(DLG_SAVEREC, _ris_dirty = false);
else
cantwrite_box(fn);
return done;
}
bool TEdit_mask::save_if_dirty_ris()
{
bool ok = true;
if (_ris_dirty)
{
const KEY k = yesnocancel_box(TR("La risorsa risulta modificata:\nSi desidera salvarla prima di continuare?"));
if (k == K_YES)
save_ris();
ok = k != K_ESC;
}
return ok;
}
bool TEdit_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case DLG_SAVEREC:
if (e == fe_button && _ris_dirty)
save_ris();
break;
case DLG_FIRSTREC:
if (e == fe_button && save_if_dirty_ris())
{
_ps.move_first();
load_ris();
}
return false;
case DLG_PREVREC:
if (e == fe_button && save_if_dirty_ris())
{
_ps.move_prev();
load_ris();
}
return false;
case DLG_FINDREC:
if (e == fe_button)
select_ris(true);
return false;
case DLG_NEXTREC:
if (e == fe_button && save_if_dirty_ris())
{
_ps.move_next();
load_ris();
}
return false;
case DLG_LASTREC:
if (e == fe_button && save_if_dirty_ris())
{
_ps.move_last();
load_ris();
}
return false;
case F_CODRIS:
if (e == fe_button)
select_ris(false);
if (e == fe_modify && save_if_dirty_ris())
{
const long mat = atol(o.get());
if (_ps.find(mat))
load_ris();
else
return error_box("Matricola inesistente");
}
break;
case F_DESRIS:
if (e == fe_button)
select_ris(true);
break;
case F_SHEET:
if (e == se_query_del || e == se_query_add)
return false;
if (e == se_notify_modify)
enable(DLG_SAVEREC, _ris_dirty = true);
if (e == fe_close)
return save_if_dirty_ris();
break;
default: break;
}
return true;
}
TEdit_mask::TEdit_mask(TRP_set& ps) : TAutomask("ci2400e"), _ps(ps), _ris_dirty(false)
{
TSheet_field& s = sfield(F_SHEET);
TISAM_recordset ore("USE &ORE");
for (bool good = ore.move_first(); good; good = ore.move_next())
{
const TString4 codice = ore.get("S1").as_string().left(2);
if (codice.full())
{
const TString& tipo = ore.get("S6").as_string();
if (tipo.full() && _tipi.find(codice) < 0)
_tipi.add(codice);
}
}
_tipi.sort();
short last_id = 102;
const TMask& sm = s.sheet_mask();
for (last_id = 108; sm.id2pos(last_id) > 0; last_id++);
last_id -= 2;
int i = 0;
short id = 102;
for (i = 0; id <= last_id; i++, id++)
{
if (i < _tipi.items())
{
const TString& t = _tipi.row(i);
s.set_column_header(i+1, t);
TEdit_field& f = sm.efield(id);
f.set_prompt(t);
}
else
s.enable_column(id, false);
}
const long mat = ini_get_int(CONFIG_DITTA, "ci", "RILPRE_RIS");
if (_ps.find(mat) || _ps.move_first())
load_ris();
else
error_box(TR("Formato file paghe non valido"));
}
////////////////////////////////////////////////////////////////////////////
// Maschera parametri
////////////////////////////////////////////////////////////////////////////
class TPaghe_mask : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TPaghe_mask();
};
bool TPaghe_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_ANNO:
case F_MESE:
if (e == fe_init || e == fe_modify)
{
TFilename n = get(121);
TString16 f; f.format("RP%4d%02d.txt", get_int(F_ANNO), get_int(F_MESE));
n.add(f);
enable(DLG_EDIT, n.exist());
} else
if (e == fe_close)
{
const int anno = get_int(F_ANNO);
const int mese = get_int(F_MESE);
if (anno < 2000 || mese < 1)
return error_box(TR("Specificare un anno ed un mese validi"));
}
break;
case DLG_EDIT:
if (e == fe_button)
{
TFilename n = get(121);
TString16 f; f.format("RP%4d%02d.txt", get_int(F_ANNO), get_int(F_MESE));
n.add(f);
TRP_set ps(1030, 1);
if (ps.load(n))
{
TEdit_mask em(ps);
em.run();
}
else
cantread_box(n);
}
break;
case DLG_EXPORT:
if (e == fe_button)
{
TFilename n = get(121);
TString16 f; f.format("RP%4d%02d.txt", get_int(F_ANNO), get_int(F_MESE));
n.add(f);
TRP_set ps(1030, 1);
if (ps.load(n))
{
TRP_xlset xls(ps);
n.ext("xls");
if (xls.save_as(n, fmt_html))
goto_url(n);
}
}
break;
default: break;
}
return true;
}
TPaghe_mask::TPaghe_mask() : TAutomask(TR("Esportazione ore"), 1, 64, 7)
{
add_button_tool(DLG_OK, PR("Esporta"), TOOL_ELABORA);
add_button_tool(DLG_EDIT, PR("Modifica"), TOOL_EDIT);
add_button_tool(DLG_EXPORT, PR("Excel"), TOOL_EXCEL);
add_button_tool(DLG_CANCEL, "", TOOL_CANCEL);
add_number(F_ANNO, 0, PR("Anno "), 1, 1, 4).check_type(CHECK_REQUIRED);
add_list (F_MESE, 0, PR("Mese "), 21, 1,12, "M");
add_number(111, 0, PR("Ditta "), 1, 2, 4, "Z").check_type(CHECK_REQUIRED); // 1030
add_number(112, 0, PR("Filiale "), 21, 2, 2, "Z").check_type(CHECK_REQUIRED); // 01
add_string(121, 0, PR("Cartella "), 1, 3, 260, "", 50).check_type(CHECK_REQUIRED);
add_boolean(113, 0, TR("Esportazione completa (comprese ore già esportate)"), 1, 4);
set_handlers();
}
////////////////////////////////////////////////////////////////////////////
// Procedura esportazione
////////////////////////////////////////////////////////////////////////////
bool esportazione_paghe(int anno, int mese)
{
TPaghe_mask m;
m.set(F_ANNO, anno);
m.set(F_MESE, mese);
int ditta = 1030, filiale = 1;
m.set(111, ini_get_int(CONFIG_DITTA, "ci", "RILPRE_DIT", ditta));
m.set(112, ini_get_int(CONFIG_DITTA, "ci", "RILPRE_FIL", filiale));
TFilename n; n.tempdir();
m.set(121, ini_get_string(CONFIG_DITTA, "ci", "RILPRE_DIR", n));
if (m.run() != K_ENTER)
return false;
const bool all = m.get_bool(113);
ini_set_int (CONFIG_DITTA, "ci", "RILPRE_DIT", ditta = m.get_int(111));
ini_set_int (CONFIG_DITTA, "ci", "RILPRE_FIL", filiale = m.get_int(112));
ini_set_string(CONFIG_DITTA, "ci", "RILPRE_DIR", n = m.get(121));
TString16 f; f.format("RP%4d%02d.txt", anno, mese);
if (n.blank() || !n.exist())
n.tempdir();
n.add(f);
const TDate dal(1, mese, anno);
TDate al(dal); al.set_end_month();
TString query;
query << "USE RILORE KEY 2"
<< "\nSELECT (TIPORA='R')";
if (!all) // Export all?
query << "&&(INVPAG!='X')";
query << "\nFROM TIPO=C DADATA=" << dal << "\nTO TIPO=C DADATA=" << al;
TISAM_recordset ore(query);
TRP_set rp(ditta, filiale);
if (!all)
rp.load(n);
TString_array tipi;
TLog_report log(TR("Esportazione ore"));
log.kill_duplicates();
TLocalisamfile& file = ore.cursor()->file();
const TRectype& curr = file.curr();
const TRecnotype tot = ore.items();
TString msg;
if (tot > 0)
{
msg.format(FR("Elaborazione di %ld rilevazioni dal %s al %s"), tot, dal.stringa(), al.stringa());
log.log(0, msg);
TProgress_monitor pi(tot, log.title());
for (bool go = ore.move_first(); go; go = ore.move_next())
{
const TString4 tpora = curr.get("TPORA");
const TRectype& tpore = cache().get("&ORE", tpora);
const TString4 tipo_ora = tpore.get("S1").left(2); // Codice esterno Zucchetti
if (tipo_ora.blank())
{
msg.format("Tipo ora '%s' non codificata per l'esportazione", (const char*)tpora);
log.log(1, msg);
continue; // Ignora ora non codificata
}
const real qta = curr.get_real("QTAORE") * CENTO;
if (qta<=ZERO)
continue;
const TString8 matricola = curr.get("CODICE");
if (!rp.find_or_create(matricola))
{
msg.format(FR("Risorsa '%s' priva del numero di matricola"), (const char*)matricola);
log.log(2, msg);
continue;
}
rp.set("DATAINI", dal.string(brief, '\0'));
rp.set("DATAFIN", al.string(brief, '\0'));
const int gg = curr.get_date("DADATA").day();
int i = 0; // ore ordinarie
TString16 fld;
const TString& tipologia = tpore.get("S6");
if (tipologia.blank()) // ordinari
fld.format("ORE_ORDIN_%02d", gg);
else
{
for (i = 1; i <= 6; i++)
{
fld.format("SIGLA_PRES%d_%02d", i, gg);
TString4 to = rp.get(fld).as_string();
if (to.blank())
rp.set(fld, to = tipo_ora);
if (to == tipo_ora)
break;
}
fld.format("ORE_GIUST%d_%02d", i, gg);
}
if (i <= 6)
{
long val = rp.get(fld).as_int();
val += qta.integer();
rp.set(fld, val);
file.put("INVPAG", true);
file.rewrite();
}
else
log.log(2, TR("Si possono esportare al massimo 6 tipi ora lo stesso giorno"));
}
}
msg.format(FR("Sono state generate %ld righe"), rp.items());
log.log(0, msg);
log.preview();
bool done = !rp.empty();
if (done)
{
done = rp.save_as(n);
if (done)
message_box(FR("E' stato generato il file %s con %ld record."), (const char*)n, rp.items());
else
error_box(FR("Impossibile generare il file %s"), (const char*)n);
}
return done;
}

6
ci/ci2401.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __CI2401_H
#define __CI2401_H
bool esportazione_paghe(int anno, int mese);
#endif