1995-12-11 11:22:47 +00:00
|
|
|
|
|
|
|
#include "../cg/saldacon.h"
|
|
|
|
#include <pagsca.h>
|
|
|
|
#include <scadenze.h>
|
|
|
|
#include <partite.h>
|
|
|
|
|
|
|
|
#include "sc21pec.h"
|
|
|
|
#include "sc2102.h"
|
|
|
|
#include "sc2402.h"
|
|
|
|
|
|
|
|
#include <causali.h>
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSol_row
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TSol_row::TSol_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata): _num_prot(0) {
|
|
|
|
_riga = row.get_int(PART_NRIGA);
|
|
|
|
_rata = rata;
|
|
|
|
|
|
|
|
_data = data;
|
|
|
|
_causale = row.get(PART_CODCAUS);
|
|
|
|
_data_doc = row.get(PART_DATADOC);
|
|
|
|
_num_prot = row.get_long(PART_PROTIVA);
|
|
|
|
_importo = imp; _importo.normalize();
|
|
|
|
_totale = row.get_real(PART_IMPTOTPAG);
|
|
|
|
|
|
|
|
_valuta.get(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
TSol_row::TSol_row(const char* desc, const TImporto& imp): _num_prot(0) {
|
|
|
|
_descrizione = desc;
|
|
|
|
_importo = imp; _importo.normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// le righe dell'estratto conto sono ordinate per data, riga partita, numero rata,
|
|
|
|
// posizione iniziale nell'array (in caso di uguaglianza di tutto il resto)
|
|
|
|
int TSol_row::compare(const TSortable& s) const {
|
|
|
|
const TSol_row& r = (const TSol_row&)s;
|
|
|
|
int c = 0;
|
|
|
|
if (_data == r._data) {
|
|
|
|
c = r._riga - _riga;
|
|
|
|
if (c == 0) c = r._rata - _rata;
|
|
|
|
} else c = _data < r._data ? +1 : -1;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TSol_row::print_on(TPrint_section& body) {
|
|
|
|
TSol_form& form = (TSol_form&)body.form();
|
|
|
|
|
|
|
|
TForm_item& causale = body.find_field(PEC_CODCAUS);
|
|
|
|
causale.set(_causale);
|
|
|
|
if (_causale.not_empty() && _descrizione.empty()) {
|
|
|
|
TDecoder& causali = form.causali();
|
|
|
|
_descrizione = causali.decode(_causale);
|
|
|
|
}
|
|
|
|
|
|
|
|
TForm_item& descr = body.find_field(PEC_DESCR1);
|
|
|
|
descr.set(_descrizione);
|
|
|
|
|
|
|
|
TForm_item& datadoc = body.find_field(PEC_DATADOC);
|
|
|
|
datadoc.set(_data_doc.string());
|
|
|
|
|
|
|
|
TForm_item& numdoc = body.find_field(PEC_NUMDOC);
|
|
|
|
numdoc.set(_num_doc);
|
|
|
|
|
|
|
|
TForm_item& numprot = body.find_field(PEC_PROTIVA);
|
|
|
|
TString16 protiva; protiva << _num_prot;
|
|
|
|
numprot.set(protiva);
|
|
|
|
|
|
|
|
TForm_item& datapag = body.find_field(PEC_DATAPAG);
|
|
|
|
datapag.set(_data.string());
|
|
|
|
|
|
|
|
const real& imp = _importo.valore();
|
|
|
|
TForm_item& dare = body.find_field(PEC_DARE);
|
|
|
|
TForm_item& avere = body.find_field(PEC_AVERE);
|
|
|
|
|
|
|
|
if (_importo.sezione() == 'D') {
|
|
|
|
dare.set(imp.string());
|
|
|
|
avere.set("");
|
|
|
|
} else {
|
|
|
|
avere.set(imp.string());
|
|
|
|
dare.set("");
|
|
|
|
}
|
|
|
|
|
|
|
|
TForm_item& scaduto = body.find_field(PEC_SCADUTO);
|
|
|
|
scaduto.set(_scaduto.string());
|
|
|
|
|
|
|
|
TForm_item& cambio = body.find_field(PEC_CAMBIO);
|
|
|
|
cambio.set(_valuta.cambio().string());
|
|
|
|
|
|
|
|
TForm_item& datacambio = body.find_field(PEC_DATACAM);
|
|
|
|
datacambio.set(_valuta.data().string());
|
|
|
|
|
|
|
|
body.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int val_compare(const void* o1, const void* o2) {
|
|
|
|
const THash_object* h1 = (const THash_object*)o1;
|
|
|
|
const THash_object* h2 = (const THash_object*)o2;
|
|
|
|
const TString& s1 = (const TString&)h1->obj();
|
|
|
|
const TString& s2 = (const TString&)h2->obj();
|
|
|
|
return s2.compare(s1, -1, TRUE); // same as stricmp(s1, s2) in reverse order
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSol_array
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TSol_array::calcola_scaduto(const TRiga_scadenze& rata, real& scaduto) const {
|
|
|
|
const TPartita& game = rata.partita();
|
|
|
|
TImporto imp_scaduto = rata.importo(TRUE);
|
|
|
|
|
|
|
|
const char* const field = rata.in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
|
|
TImporto imp;
|
|
|
|
|
|
|
|
for (int p = rata.last(); p > 0; p = rata.pred(p)) {
|
|
|
|
const TRectype& pag = rata.row(p);
|
|
|
|
const TRiga_partite& sum = game.riga(pag.get_int(PAGSCA_NRIGP));
|
|
|
|
const tipo_movimento tm = sum.tipo();
|
|
|
|
if (tm != tm_insoluto && tm != tm_pagamento_insoluto) {
|
|
|
|
imp.set(sum.sezione(), pag.get_real(field));
|
|
|
|
imp_scaduto += imp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const char sezione = game.conto().tipo() == 'C' ? 'D' : 'A';
|
|
|
|
imp_scaduto.normalize(sezione);
|
|
|
|
scaduto = imp_scaduto.valore();
|
|
|
|
}
|
|
|
|
|
|
|
|
TSol_row& TSol_array::new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int n) {
|
|
|
|
if (n == 0) n = items();
|
|
|
|
TSol_row* riga = new TSol_row(row, data, imp, n);
|
|
|
|
add(riga, n);
|
|
|
|
return *riga;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TSol_array::add_row(const TRiga_partite& row) {
|
|
|
|
if (row.is_fattura()) {
|
|
|
|
for (int r = 1; r <= row.rate(); r++) {
|
|
|
|
const TRiga_scadenze& rata = row.rata(r);
|
|
|
|
const TDate data(rata.get(SCAD_DATASCAD));
|
|
|
|
if (data <= form().data_limite_operazione()) {
|
|
|
|
TSol_row& rec = new_row(row, data, rata.importo(TRUE), r);
|
|
|
|
if (data <= form().data_limite_scaduto()) {
|
|
|
|
real s;
|
|
|
|
calcola_scaduto(rata, s);
|
|
|
|
rec.scaduto(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const TDate data(row.get(PART_DATAPAG));
|
|
|
|
if (data <= form().data_limite_operazione()) {
|
|
|
|
const TImporto imp(row.importo(FALSE, 0x1));
|
|
|
|
new_row(row, data, imp);
|
|
|
|
|
|
|
|
const TImporto abbuoni(row.importo(FALSE, 0x2));
|
|
|
|
if (!abbuoni.is_zero()) {
|
|
|
|
TSol_row& r = new_row(row, data, abbuoni);
|
|
|
|
const TForm_item& desc_abb = form().find_field('B', odd_page, 302);
|
|
|
|
r.descrizione(desc_abb.prompt());
|
|
|
|
}
|
|
|
|
|
|
|
|
const TImporto diffcam(row.importo(FALSE, 0x4));
|
|
|
|
if (!diffcam.is_zero()) {
|
|
|
|
TSol_row& r = new_row(row, data, diffcam);
|
|
|
|
const TForm_item& desc_dif = form().find_field('B', odd_page, 303);
|
|
|
|
r.descrizione(desc_dif.prompt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TSol_array::TSol_array(const TPartita& game, const TSol_form* f): _form(f) {
|
|
|
|
for (int r = game.last(); r > 0; r = game.pred(r)) add_row(game.riga(r));
|
|
|
|
sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSol_form: form speciale per solleciti
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TSol_form* TSol_form::_form = NULL;
|
|
|
|
|
|
|
|
void TSol_form::sol_header_handler(TPrinter& pr) {
|
|
|
|
TPrint_section& head = _form->section('H');
|
|
|
|
head.reset();
|
|
|
|
pr.resetheader();
|
|
|
|
|
|
|
|
head.update();
|
|
|
|
for (word j = 0; j < head.height(); j++) pr.setheaderline(j, head.row(j));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TSol_form::sol_footer_handler(TPrinter& pr) {
|
|
|
|
TPrint_section& foot = _form->section('F');
|
|
|
|
pr.resetfooter();
|
|
|
|
|
|
|
|
const word MAXTOT = 32;
|
|
|
|
THash_object* tot[MAXTOT];
|
|
|
|
|
|
|
|
// i totali sono in un assoc array disordinato per cui li copio in un array e li ordino
|
|
|
|
// alfabeticamente in base al loro codice valuta
|
|
|
|
TTotalizer& totali = _form->totali();
|
|
|
|
totali.restart();
|
|
|
|
|
|
|
|
word numtot = 0;
|
|
|
|
for (THash_object* obj = totali.get_hashobj(); numtot < MAXTOT && obj != NULL; obj = totali.get_hashobj()) tot[numtot++] = obj;
|
|
|
|
qsort(tot, numtot, sizeof(THash_object*), val_compare);
|
|
|
|
|
|
|
|
if (numtot > foot.height()) numtot = foot.height();
|
|
|
|
|
|
|
|
TPrint_section& body = _form->section('B');
|
|
|
|
for (word j = 0; j < numtot; j++) {
|
|
|
|
const TString& key = tot[j]->key();
|
|
|
|
TImporto& imp = (TImporto&)tot[j]->obj();
|
|
|
|
TSol_row r(key, imp.normalize());
|
|
|
|
r.print_on(body);
|
|
|
|
const TPrintrow& ri = body.row(0);
|
|
|
|
pr.setfooterline(j, ri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TSol_form::print_game(const TPartita& game)
|
|
|
|
{
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
TSol_array righe(game, this);
|
|
|
|
|
|
|
|
TPrinter& pr = printer();
|
|
|
|
TPrintrow prow;
|
|
|
|
|
|
|
|
TPrint_section& body = section('B');
|
|
|
|
|
|
|
|
TImporto saldo;
|
|
|
|
|
|
|
|
// stampa le righe di partita
|
|
|
|
for (int r = 0; r < righe.items(); r++)
|
|
|
|
{
|
|
|
|
TSol_row& riga = righe.row(r);
|
|
|
|
|
|
|
|
if (pr.rows_left() < body.height())
|
|
|
|
pr.formfeed();
|
|
|
|
|
|
|
|
riga.print_on(body);
|
|
|
|
pr.print(body.row(0));
|
|
|
|
|
|
|
|
totali().add(riga.importo(), ZERO, ZERO, riga.valuta().codice());
|
|
|
|
|
|
|
|
saldo += riga.importo();
|
|
|
|
ok = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
saldo.normalize();
|
|
|
|
|
|
|
|
const TForm_item& desc_sld = body.find_field(301);
|
|
|
|
TSol_row sld(desc_sld.prompt(), saldo);
|
|
|
|
sld.print_on(body);
|
|
|
|
|
|
|
|
// salta una riga vuota
|
|
|
|
TPrintrow vuota;
|
|
|
|
pr.print(vuota);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
TSol_form::TSol_form(const TSol_mask& m, short datafld): TForm(BASE_EC_PROFILE, m.get_prof_code()), _causali(LF_CAUSALI, CAU_CODCAUS, CAU_DESCR) {
|
|
|
|
_form = this;
|
|
|
|
|
|
|
|
_lingua = m.get_prof_lang();
|
|
|
|
|
|
|
|
TCursor_sheet& cs = m.cur_sheet();
|
|
|
|
_cursore = cs.cursor();
|
|
|
|
|
|
|
|
_dlo = _dls = m.get(datafld); // prende il campo con la data limite sollecito
|
|
|
|
|
|
|
|
TPrinter& pr = printer();
|
|
|
|
|
|
|
|
pr.setheaderhandler(sol_header_handler);
|
|
|
|
pr.headerlen(section('H').height());
|
|
|
|
|
|
|
|
pr.setfooterhandler(sol_footer_handler);
|
|
|
|
pr.footerlen(section('F').height());
|
|
|
|
}
|
|
|
|
|
|
|
|
TSol_form::~TSol_form() {
|
|
|
|
TPrinter& pr = printer();
|
|
|
|
pr.setheaderhandler(NULL);
|
|
|
|
pr.setfooterhandler(NULL);
|
|
|
|
_form = NULL;
|
|
|
|
}
|