Corretto conflitto su pagament e corrette maschere saldaconto

git-svn-id: svn://10.65.10.50/trunk@2004 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-10-25 09:34:53 +00:00
parent c50d894972
commit e77565deb7
16 changed files with 2078 additions and 1808 deletions

View File

@ -8,38 +8,4 @@ MENUBAR MENU_BAR(1)
MENU MENU_BAR(1) MENU MENU_BAR(1)
SUBMENU MENU_FILE "~File" SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(2)
MENU MENU_BAR(2)
SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(3)
MENU MENU_BAR(3)
SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(4)
MENU MENU_BAR(4)
SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(5)
MENU MENU_BAR(5)
SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(6)
MENU MENU_BAR(6)
SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(7)
MENU MENU_BAR(7)
SUBMENU MENU_FILE "~File"
MENUBAR MENU_BAR(8)
MENU MENU_BAR(8)
SUBMENU MENU_FILE "~File"

View File

@ -17,7 +17,8 @@
#include <rcausali.h> #include <rcausali.h>
TPrimanota_application::TPrimanota_application() TPrimanota_application::TPrimanota_application()
: _rel(NULL), _lastreg(0), _mode(0), _iva(nessuna_iva), _causale(NULL), _giornale(NULL) : _rel(NULL), _mode(0), _iva(nessuna_iva), _causale(NULL), _giornale(NULL),
_lastreg(0), _last_dreg(TODAY), _last_dcom(TODAY)
{ {
memset(_msk, 0, sizeof(_msk)); memset(_msk, 0, sizeof(_msk));
} }
@ -25,12 +26,18 @@ TPrimanota_application::TPrimanota_application()
TMask* TPrimanota_application::load_mask(int n) TMask* TPrimanota_application::load_mask(int n)
{ {
if (n == 2 && _msk[0] != NULL)
{
delete _msk[0];
_msk[0] = NULL;
}
if (_msk[n] != NULL) if (_msk[n] != NULL)
return _msk[n]; return _msk[n];
if (n < 3) if (n == 1 || n == 2)
{ {
for (int i = 3; i >= 0; i--) for (int i = 3; i > 0; i--)
{ {
if (_msk[i] != NULL) if (_msk[i] != NULL)
{ {
@ -97,8 +104,10 @@ TMask* TPrimanota_application::load_mask(int n)
// add saldaconto // add saldaconto
TSheet_field& ps = (TSheet_field&)m->field(FS_RATESHEET); TSheet_field& ps = (TSheet_field&)m->field(FS_RATESHEET);
ps.set_notify(pag_notify); ps.set_notify(pag_notify);
m->set_handler(FS_RATESHEET, pag_sheet_handler);
m->set_handler(FS_RESET, reset_handler); m->set_handler(FS_RESET, reset_handler);
m->set_handler(FS_NRATE, nrate_handler); m->set_handler(FS_NRATE, nrate_handler);
m->set_handler(FS_RECALC, recalc_handler);
m->set_handler(FS_NSCAB, codcab_handler); m->set_handler(FS_NSCAB, codcab_handler);
m->set_handler(FS_VSCAB, codcab_handler); m->set_handler(FS_VSCAB, codcab_handler);
} }
@ -139,25 +148,27 @@ TMask* TPrimanota_application::load_mask(int n)
break; break;
} }
return _msk[n] = m; _msk[n] = m;
return m;
} }
void TPrimanota_application::open_files(int logicnum, ...)
{
va_list marker;
va_start(marker, logicnum);
while (logicnum > 0)
{
CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
_file.add(new TLocalisamfile(logicnum), logicnum);
logicnum = va_arg(marker, int);
}
}
bool TPrimanota_application::user_create() bool TPrimanota_application::user_create()
{ {
_tabcom = new TLocalisamfile(LF_TABCOM); open_files(LF_TABCOM, LF_TAB, LF_CAUSALI, LF_RCAUSALI, LF_CLIFO, LF_PCON, 0);
_tab = new TLocalisamfile(LF_TAB); open_files(LF_ATTIV, LF_SALDI, LF_COMUNI, LF_OCCAS, LF_NDITTE, 0);
_caus = new TLocalisamfile(LF_CAUSALI); open_files(LF_SCADENZE, LF_PAGSCA, 0);
_rcaus = new TLocalisamfile(LF_RCAUSALI);
_clifo = new TLocalisamfile(LF_CLIFO);
_pcon = new TLocalisamfile(LF_PCON);
_attiv = new TLocalisamfile(LF_ATTIV);
_saldo = new TLocalisamfile(LF_SALDI);
_comuni = new TLocalisamfile(LF_COMUNI);
_occas = new TLocalisamfile(LF_OCCAS);
_nditte = new TLocalisamfile(LF_NDITTE);
_scadenze = new TLocalisamfile(LF_SCADENZE);
_pagamenti = new TLocalisamfile(LF_PAGSCA);
_rel = new TMovimentoPN; _rel = new TMovimentoPN;
_rel->add(LF_PARTITE, "NREG=NUMREG", 2); // Collega la partita aperta dalla fattura _rel->add(LF_PARTITE, "NREG=NUMREG", 2); // Collega la partita aperta dalla fattura
@ -191,19 +202,7 @@ bool TPrimanota_application::user_destroy()
delete _giornale; delete _giornale;
delete _causale; delete _causale;
delete _rel; delete _rel;
close_files();
delete _scadenze;
delete _nditte;
delete _occas;
delete _comuni;
delete _saldo;
delete _attiv;
delete _pcon;
delete _clifo;
delete _rcaus;
delete _caus;
delete _tab;
delete _tabcom;
return TRUE; return TRUE;
} }
@ -452,6 +451,18 @@ void TPrimanota_application::init_mask(TMask& m)
m.show(-4, valintra); m.show(-4, valintra);
m.show(F_CODIVA, m.mode() == MODE_INS); // Codice IVA standard m.show(F_CODIVA, m.mode() == MODE_INS); // Codice IVA standard
const TPartita* game = partite().first();
const bool scad_free = game == NULL || !game->esistono_abbuoni_diffcam(m.get_long(F_NUMREG));
m.enable(DLG_DELREC, scad_free); // Disabilita tasto cancella
m.enable(-1, scad_free); // Disabilita cliente
m.enable(-2, scad_free);
m.enable(F_CODPAG, scad_free); // Disabilita codice pagamento
m.enable(FS_RESET, scad_free); // Disabilita tasto di reset
if (!scad_free) m.set(FS_RECALC, "", TRUE);
m.enable(FS_RECALC, scad_free); // Disabilita ricalcolo automatico
} }
// Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_DATACAMBIO (GROUP 3) // Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_DATACAMBIO (GROUP 3)
@ -463,10 +474,8 @@ void TPrimanota_application::init_query_mode(TMask& m)
{ {
enable_menu_item(M_FILE_PRINT); enable_menu_item(M_FILE_PRINT);
const TDate inco(TODAY); m.set(F_DATAREG, _last_dreg);
const char* oggi = inco.string(); m.set(F_DATACOMP, _last_dcom);
m.set(F_DATAREG, oggi);
m.set(F_DATACOMP, oggi);
} }
@ -483,7 +492,7 @@ void TPrimanota_application::fill_sheet(TMask& m) const
TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA); TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA);
for (int r = ivas.items(); r < 16; r++) ivas.row(r); for (int r = ivas.items(); r < 16; r++) ivas.row(r);
ivas.enable_column(2, _iva == iva_acquisti); // Tipo detrazione ivas.enable_column(2, _iva == iva_acquisti); // Tipo detrazione
ivas.enable_column(4, !m.insert_mode()); // Tipo costo ricavo ivas.enable_column(4, !m.insert_mode()); // Tipo costo ricavo
} }
} }
@ -552,11 +561,6 @@ void TPrimanota_application::init_modify_mode(TMask& m)
{ {
const long numreg = m.get_long(F_NUMREG); const long numreg = m.get_long(F_NUMREG);
partite().add_numreg(numreg); partite().add_numreg(numreg);
if (iva() != nessuna_iva)
{
const TPartita* game = partite().first();
m.enable(DLG_DELREC, game == NULL || !game->esistono_abbuoni_diffcam());
}
} }
calcola_saldo(); // Verifica eventuali sbilanci contabili calcola_saldo(); // Verifica eventuali sbilanci contabili
@ -671,8 +675,9 @@ int TPrimanota_application::read(TMask& m)
const int tm = causale().tipomov(); const int tm = causale().tipomov();
if (tm != 0 && tm != 2) // Ci sono scadenze if (tm != 0 && tm != 2) // Ci sono scadenze
{ {
const TString16 cp(m.get(F_CODPAG));
const TString16 dt(m.get(F_DATAREG)); const TString16 dt(m.get(F_DATAREG));
set_pagamento(m.get(F_CODPAG), dt); set_pagamento(cp, dt);
if (!read_scadenze(m)) if (!read_scadenze(m))
set_scadenze(m); set_scadenze(m);
} }
@ -846,6 +851,9 @@ int TPrimanota_application::write(const TMask& m)
if (lasterr == NOERR) if (lasterr == NOERR)
mask2rel(m); // Altrimenti raddoppia i saldi! mask2rel(m); // Altrimenti raddoppia i saldi!
_last_dreg = m.get(F_DATAREG);
_last_dcom = m.get(F_DATACOMP);
const int err = _rel->write(TRUE); const int err = _rel->write(TRUE);
if (err == NOERR) if (err == NOERR)
{ {

View File

@ -49,7 +49,6 @@ DATE F_DATAREG
BEGIN BEGIN
PROMPT 1 6 "Data operazione " PROMPT 1 6 "Data operazione "
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
FLAGS "A"
HELP "Data in cui viene registrata l'operazione" HELP "Data in cui viene registrata l'operazione"
MESSAGE COPY,F_ANNOIVA,7,10 MESSAGE COPY,F_ANNOIVA,7,10
END END
@ -65,7 +64,6 @@ BEGIN
PROMPT 1 7 "Data di competenza " PROMPT 1 7 "Data di competenza "
HELP "Data di competenza dell'operazione" HELP "Data di competenza dell'operazione"
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
FLAGS "A"
END END
NUMBER F_ANNOES 4 NUMBER F_ANNOES 4

View File

@ -106,7 +106,6 @@ BEGIN
FIELD PROVVIS FIELD PROVVIS
ITEM " |No (movimento normale)" ITEM " |No (movimento normale)"
ITEM "P|Si (cancellabile)" ITEM "P|Si (cancellabile)"
MESSAGE COPY,K_PROVVISORIO
END END
STRING F_TIPODOC 2 STRING F_TIPODOC 2

109
cg/cg2100n.uml Executable file
View File

@ -0,0 +1,109 @@
#include "cg2100p.h"
PAGE "Nuova partita" -1 -1 48 10
RADIOBUTTON P_NUOVO 1 21
BEGIN
PROMPT 0 0 "@BTipo movimento"
ITEM "1|Fattura"
MESSAGE ENABLE,P_CODPAG
ITEM "2|Nota credito"
MESSAGE DISABLE,P_CODPAG
ITEM "3|Incasso/pagamento "
MESSAGE DISABLE,P_CODPAG
ITEM "5|Insoluto"
MESSAGE DISABLE,P_CODPAG
ITEM "6|Pagamento insoluto"
MESSAGE DISABLE,P_CODPAG
GROUP 1
END
NUMBER P_ANNO 4
BEGIN
PROMPT 22 1 "Partita "
FLAGS "A"
CHECKTYPE REQUIRED
WARNING "Inserire l'anno di riferimento partita"
END
STRING P_NUMERO 7
BEGIN
PROMPT 40 1 ""
FLAGS "U"
CHECKTYPE REQUIRED
WARNING "Inserire il numero di riferimento partita"
END
TEXT DLG_NULL
BEGIN
PROMPT 22 2 "Sezione"
END
RADIOBUTTON P_SEZIONE 1 20
BEGIN
PROMPT 31 1 ""
ITEM "D|Dare"
ITEM "A|Avere"
FLAGS "Z"
GROUP 1
END
NUMBER P_RESIDUO 15
BEGIN
PROMPT 22 3 "Importo "
PICTURE "."
GROUP 1
END
STRING P_CODPAG 4
BEGIN
PROMPT 22 4 "Pagamento "
FLAGS "UZ"
USE %CPG
INPUT CODTAB P_CODPAG
DISPLAY "Codice" CODTAB
DISPLAY "Descrizione@50" S0
OUTPUT P_CODPAG CODTAB
CHECKTYPE REQUIRED
ADD RUN ba3 -6
GROUP 1
WARNING "Codice pagamento assente"
END
STRING P_NUMDOC 7
BEGIN
PROMPT 22 5 "Documento "
FLAGS "U"
GROUP 1
END
DATE P_DATADOC
BEGIN
PROMPT 22 6 "Data "
FLAGS "A"
CHECKTYPE REQUIRED
WARNING "Inserire una data per il movimento extra-contabile"
GROUP 1
END
STRING P_DESCR 50 34
BEGIN
PROMPT 1 7 "Descrizione "
WARNING "Inserire una descrizione per il movimento extra-contabile"
CHECKTYPE REQUIRED
GROUP 1
END
BUTTON DLG_OK 10 2
BEGIN
PROMPT -12 -1 ""
END
BUTTON DLG_CANCEL 10 2
BEGIN
PROMPT -22 -1 ""
END
ENDPAGE
ENDMASK

View File

@ -9,12 +9,19 @@
#define P_VALUTA 109 #define P_VALUTA 109
#define P_DATACAMBIO 110 #define P_DATACAMBIO 110
#define P_CAMBIO 111 #define P_CAMBIO 111
#define P_SHOWALL 180 #define P_SHOWALL 180
#define P_SCAMBIO 181
#define P_NUOVO 182 #define P_NUOVO 182
#define P_PARTITE 201 #define P_PARTITE 201
#define P_SCADENZE 202 #define P_SCADENZE 202
// Campi aggiuntivi per extra-contabile
#define P_DATADOC 112
#define P_SEZIONE 113
#define P_CODPAG 114
#define P_NUMDOC 115
// Scadenze // Scadenze
#define S_ANNO 101 #define S_ANNO 101

View File

@ -209,12 +209,12 @@ ENDMASK
PAGE "Sheet Scadenze" -1 -1 68 10 PAGE "Sheet Scadenze" -1 -1 68 10
STRING 101 4 NUMBER 101 4
BEGIN BEGIN
PROMPT 1 1 "Numero riga " PROMPT 1 1 "Numero riga "
END END
STRING 102 4 NUMBER 102 4
BEGIN BEGIN
PROMPT 41 1 "Numero rata " PROMPT 41 1 "Numero rata "
END END

View File

@ -260,6 +260,7 @@ BEGIN
DISPLAY "Descrizione@50" S0 DISPLAY "Descrizione@50" S0
OUTPUT S_CODDESC CODTAB OUTPUT S_CODDESC CODTAB
OUTPUT S_DESCAGG S0 OUTPUT S_DESCAGG S0
CHECKTYPE NORMAL
END END
STRING S_DESCAGG 50 STRING S_DESCAGG 50

View File

@ -888,7 +888,7 @@ bool TPrimanota_application::imponibile_handler(TMask_field& f, KEY key)
const real imponibile(f.get()); const real imponibile(f.get());
real imposta = abs(imponibile) * percent / 100.0; imposta.ceil(); real imposta = abs(imponibile) * percent / 100.0; imposta.ceil();
if (imponibile.sign() < 0) imposta = -imposta; if (imponibile.sign() < 0) imposta = -imposta;
m.set(104, imposta.string()); m.set(104, imposta);
} }
} }
@ -947,7 +947,7 @@ bool TPrimanota_application::detrazione_handler(TMask_field& f, KEY key)
bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key) bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key)
{ {
if (key == K_ENTER || key == K_TAB) if ((key == K_ENTER || key == K_TAB) && f.dirty())
{ {
const real imponibile(f.mask().get(101)); const real imponibile(f.mask().get(101));
const real& percent = app().causale().corrispettivi() ? ZERO : cod2IVA(f.mask()); const real& percent = app().causale().corrispettivi() ? ZERO : cod2IVA(f.mask());

View File

@ -27,22 +27,10 @@
class TPrimanota_application : public TRelation_application class TPrimanota_application : public TRelation_application
{ {
TMovimentoPN* _rel; TArray _file; // Tutti i fiels da usare
TLocalisamfile* _tabcom; TMovimentoPN* _rel; // Relazione principale
TLocalisamfile* _tab;
TLocalisamfile* _caus;
TLocalisamfile* _rcaus;
TLocalisamfile* _clifo;
TLocalisamfile* _pcon;
TLocalisamfile* _attiv;
TLocalisamfile* _saldo;
TLocalisamfile* _comuni;
TLocalisamfile* _occas;
TLocalisamfile* _nditte;
TLocalisamfile* _scadenze;
TLocalisamfile* _pagamenti;
TPagamento* _pag; TPagamento* _pag;
TCausale* _causale; // Causale corrente TCausale* _causale; // Causale corrente
TLibro_giornale* _giornale; // Libro giornale corrente TLibro_giornale* _giornale; // Libro giornale corrente
@ -68,6 +56,9 @@ class TPrimanota_application : public TRelation_application
long _lastreg; // Numero ultima registrazione long _lastreg; // Numero ultima registrazione
int _mode; // Modo maschera corrente int _mode; // Modo maschera corrente
TDate _last_dreg; // Ultima data registrazione inserita
TDate _last_dcom; // Ultima data competenza inserita
TBill _conto_ricavo; // Conto di ricavo del clifo TBill _conto_ricavo; // Conto di ricavo del clifo
TString_array _pag_rows; TString_array _pag_rows;
@ -114,13 +105,16 @@ class TPrimanota_application : public TRelation_application
static bool cambio_handler(TMask_field& f, KEY key); static bool cambio_handler(TMask_field& f, KEY key);
static bool reset_handler(TMask_field& f, KEY key); static bool reset_handler(TMask_field& f, KEY key);
static bool nrate_handler(TMask_field& f, KEY key); static bool nrate_handler(TMask_field& f, KEY key);
static bool recalc_handler(TMask_field& f, KEY key);
static bool codcab_handler(TMask_field& f, KEY key); static bool codcab_handler(TMask_field& f, KEY key);
static bool iva_notify(TSheet_field& s, int r, KEY key); static bool iva_notify(TSheet_field& s, int r, KEY key);
static bool iva_handler(TMask_field& f, KEY key); static bool iva_handler(TMask_field& f, KEY key);
static bool cg_notify(TSheet_field& s, int r, KEY key); static bool cg_notify(TSheet_field& s, int r, KEY key);
static bool cg_handler(TMask_field& f, KEY key); static bool cg_handler(TMask_field& f, KEY key);
static bool pag_notify(TSheet_field& s, int r, KEY key); static bool pag_notify(TSheet_field& s, int r, KEY key);
static bool pag_sheet_handler(TMask_field& f, KEY key);
void reset_sheet_row(TSheet_field& s, int n); void reset_sheet_row(TSheet_field& s, int n);
@ -152,6 +146,8 @@ protected:
TMask* load_mask(int n); TMask* load_mask(int n);
TMask& occas_mask() { return *load_mask(3); } TMask& occas_mask() { return *load_mask(3); }
void open_files(int logicnum, ...);
void close_files() { _file.destroy(); }
void mask2rel(const TMask& m); void mask2rel(const TMask& m);

View File

@ -17,15 +17,14 @@
#include <scadenze.h> #include <scadenze.h>
#include <pagsca.h> #include <pagsca.h>
bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k) bool TPrimanota_application::pag_notify(TSheet_field& ps, int r, KEY k)
{ {
TPagamento* pg = app().pagamento(); TPagamento* pg = app().pagamento();
if (pg == NULL) if (pg == NULL)
return TRUE; return TRUE;
TPagamento& pag = *pg; TPagamento& pag = *pg;
TSheet_field& ps = app().pags(); TMask* msk = &(ps.mask());
TMask* msk = &(app().curr_mask());
TString_array& rws = app().pag_rows(); TString_array& rws = app().pag_rows();
const int rdiff = atoi(msk->get(FS_RDIFFER)); const int rdiff = atoi(msk->get(FS_RDIFFER));
@ -105,34 +104,30 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
// put data as they are // put data as they are
TToken_string& trw = pag.rata(r); TToken_string& trw = pag.rata(r);
TToken_string srw = trw; TToken_string srw = trw;
if (m_perc) trw.add(newp,1);
if (m_tipo) trw.add(newt,2); if (m_tipo) trw.add(newt,2);
if (m_scad) trw.add(news,3); if (m_scad) trw.add(news,3);
if (m_imp) trw.add(newi,4); if (m_imp)
// validate the payment {
if ((ahiahi = pag.validate()) != P_OK) trw.add(newi,4);
pag.rata(r) = srw; const real p = pag.recalc_percrata(r);
ps.row(r).add(p.string(), 3);
rws.row(r) = ps.row(r);
ps.force_update(r);
}
} }
if (ahiahi) // any error? Rimetti le righe com'erano prima if (ahiahi) // any error? Rimetti le righe com'erano prima
{ {
beep(); if (recalc)
// se gli errori sono voluti, spiegali
if (!recalc)
{ {
TString256 s; beep();
pag.strerr(ahiahi,s); ps.row(r) = rws.row(r);
warning_box(s); ps.force_update(r);
} }
ps.row(r) = rws.row(r);
ps.force_update(r);
} }
else if (recalc && mod && need_recalc) else if (recalc && mod && need_recalc)
{ {
// ridefinisci lo sheet sulla base delle nuove rate // ridefinisci lo sheet sulla base delle nuove rate
pag.set_sheet(ps); pag.set_sheet(ps);
ps.force_update();
rws = ps.rows_array(); rws = ps.rows_array();
} }
} }
@ -140,6 +135,28 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
return doit; return doit;
} }
bool TPrimanota_application::pag_sheet_handler(TMask_field& f, KEY key)
{
bool ok = TRUE;
if (key == K_TAB || key == K_ENTER)
{
TPagamento* pag = app().pagamento();
if (pag != NULL)
{
const word err = pag->validate();
if (err != P_OK)
{
TString256 s;
pag->strerr(err, s);
error_box(s);
ok = FALSE;
}
}
}
return ok;
}
bool TPrimanota_application::codpag_handler(TMask_field& f, KEY key) bool TPrimanota_application::codpag_handler(TMask_field& f, KEY key)
{ {
TMask& m = f.mask(); TMask& m = f.mask();
@ -183,6 +200,19 @@ bool TPrimanota_application::reset_handler(TMask_field& f, KEY key)
return TRUE; return TRUE;
} }
bool TPrimanota_application::recalc_handler(TMask_field& f, KEY key)
{
if (key == K_SPACE)
{
const bool on = f.get().not_empty();
const TMask& m = f.mask();
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
ps.enable_column(3, on);
}
return TRUE;
}
bool TPrimanota_application::nrate_handler(TMask_field& f, KEY key) bool TPrimanota_application::nrate_handler(TMask_field& f, KEY key)
{ {
const TMask& m = f.mask(); const TMask& m = f.mask();
@ -263,14 +293,15 @@ void TPrimanota_application::set_scadenze(TMask& m)
pag.set_total(imponibile, imposta, spese); pag.set_total(imponibile, imposta, spese);
pag.set_rate_auto(); pag.set_rate_auto();
m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2"); if (m.field(FS_RECALC).enabled())
m.set(FS_NAMEPAG, pag.name()); {
m.set(FS_TIPOPR, pag.desc_tpr()); m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
m.set(FS_MCOMM, pag.mese_commerciale() ? "X" : ""); m.set(FS_NAMEPAG, pag.name());
m.set(FS_RECALC, "X", TRUE); m.set(FS_TIPOPR, pag.desc_tpr());
m.set(FS_NRATE, pag.n_rate()); m.set(FS_MCOMM, pag.mese_commerciale() ? "X" : "");
m.set(FS_RECALC, "X", TRUE);
bool new_part = TRUE; m.set(FS_NRATE, pag.n_rate());
}
TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
pag.set_sheet(ps); // prepara lo sheet pag.set_sheet(ps); // prepara lo sheet
@ -325,13 +356,11 @@ bool TPrimanota_application::read_scadenze(TMask& m)
int npart = part.prima_fattura(nreg); int npart = part.prima_fattura(nreg);
bool fromscratch = FALSE; bool fromscratch = FALSE;
bool scad_locked = FALSE;
if (npart > 0) // la gh'e' if (npart > 0) // la gh'e'
{ {
const TRiga_partite& partita = part.riga(npart); const TRiga_partite& partita = part.riga(npart);
const TRiga_scadenze& primarata = partita.rata(1); const TRiga_scadenze& primarata = partita.rata(1);
scad_locked = partita.ultima_ratapagata() > 0;
// se si e' specificato un codice pagamento diverso si rifa' da capo // se si e' specificato un codice pagamento diverso si rifa' da capo
// la follia e' che e' sulle SCADENZE, non sulle partite, naturalmente // la follia e' che e' sulle SCADENZE, non sulle partite, naturalmente
@ -352,7 +381,7 @@ bool TPrimanota_application::read_scadenze(TMask& m)
" all'ultima registrazione. Si desidera mantenere" " all'ultima registrazione. Si desidera mantenere"
" comunque la rateazione precedente"); " comunque la rateazione precedente");
// nel qual caso, of course, si disabilitano gli automatismi // nel qual caso, of course, si disabilitano gli automatismi
if(!fromscratch) m.field(FS_RECALC).set(""); if(!fromscratch) m.set(FS_RECALC, "", TRUE);
} }
} }
@ -411,17 +440,6 @@ bool TPrimanota_application::read_scadenze(TMask& m)
if (pag.tipo_prima_rata() > 3) if (pag.tipo_prima_rata() > 3)
ps.disable_cell(0,-1); ps.disable_cell(0,-1);
if (scad_locked)
{
m.disable(-1); // Disabilita cliente
m.disable(-2); // Disabilita fornitore
m.disable(-3); // Disabilita cambio
m.disable(F_CODPAG); // Disabilita codice pagamento
m.disable(FS_RESET); // Disabilita tasto di reset
m.set(FS_RECALC, "", TRUE); // Disabilita ricalcolo automatico
m.disable(FS_RECALC);
}
return TRUE; return TRUE;
} }
@ -571,7 +589,7 @@ bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k)
if (k == K_SPACE) if (k == K_SPACE)
{ {
const bool ok = app().edit_partite(m, riga); const bool ok = app().edit_partite(m, riga);
if (ok) if (ok && riga < s.items())
k = K_ENTER; k = K_ENTER;
} }
@ -666,7 +684,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam; TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
const bool empty = p.modifica_pagamento(new_pag, valuta, const bool empty = p.modifica_pagamento(new_pag, valuta,
old_ap, old_abbuono, old_diffcam, old_ap, old_abbuono, old_diffcam,
new_ap, new_abbuono, new_diffcam); new_ap, new_abbuono, new_diffcam, TRUE);
if (deleting >= 0) if (deleting >= 0)
{ {
@ -677,19 +695,23 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
{ {
const int riga_abb = type2pos(old_ap); const int riga_abb = type2pos(old_ap);
CHECK(riga_abb >= 0, "Chiss'e' fregato gli abbuoni?"); CHECK(riga_abb >= 0, "Chiss'e' fregato gli abbuoni?");
const bool empty = sub_cgs_imp(riga_abb, old_abbuono); const bool empty = add_cgs_imp(riga_abb, old_abbuono);
if (empty && new_ap != old_ap) if (empty && new_ap != old_ap)
reset_cgs_row(riga_abb); cgs().destroy(riga_abb);
if (deleting != riga_contabile) if (deleting != riga_contabile)
{ {
// Sottrae l'abbuono con la sezione invertita dalla riga contabile // Sottrae l'abbuono con la sezione invertita dalla riga contabile
add_cgs_imp(riga_contabile-1, old_abbuono); sub_cgs_imp(riga_contabile-1, old_abbuono);
} }
} }
if (new_ap != ' ') // Se ci sono abbuoni if (new_ap != ' ') // Se ci sono abbuoni
{ {
const riga_abb = type2pos(new_ap); const riga_abb = type2pos(new_ap);
new_abbuono.swap_section();
new_abbuono.normalize();
if (riga_abb < 0) if (riga_abb < 0)
{ {
const int rc = new_ap == 'A' ? 9 : 8; const int rc = new_ap == 'A' ? 9 : 8;
@ -712,8 +734,8 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
if (old_diffcam != new_diffcam) if (old_diffcam != new_diffcam)
{ {
const int riga_diffcam = type2pos('C'); const int riga_diffcam = type2pos('C');
TImporto grow_diffcam(new_diffcam); TImporto grow_diffcam(old_diffcam);
grow_diffcam -= old_diffcam; grow_diffcam -= new_diffcam;
grow_diffcam.normalize(); grow_diffcam.normalize();
if (riga_diffcam < 0) if (riga_diffcam < 0)
@ -725,7 +747,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
else else
{ {
const bool empty = add_cgs_imp(riga_diffcam, grow_diffcam); const bool empty = add_cgs_imp(riga_diffcam, grow_diffcam);
if (empty) reset_cgs_row(riga_diffcam); if (empty) cgs().destroy(riga_diffcam);
} }
if (deleting != riga_contabile) if (deleting != riga_contabile)

View File

@ -1,8 +1,9 @@
#include <execp.h>
#include <mailbox.h>
#include <defmask.h> // Serve per DLG_NEWREC #include <defmask.h> // Serve per DLG_NEWREC
#ifdef __EXTRA__ #ifndef __EXTRA__
#else
#include "cg2102.h" // Applicazione di prima nota #include "cg2102.h" // Applicazione di prima nota
#include "cg2100.h" // Campi maschere prima nota #include "cg2100.h" // Campi maschere prima nota
@ -168,17 +169,24 @@ class TGame_mask : public TMask
int _numrig; // Riga contabile corrente (prima = 1!) int _numrig; // Riga contabile corrente (prima = 1!)
TImporto _importo; // Importo riga contabile TImporto _importo; // Importo riga contabile
int _riga_partite; // Riga corrente delle partite int _riga_partite; // Riga corrente delle partite
bool _changed;
int _tipomov; // Dati per la creazione di un nuovo movimento
char _sezione;
TDate _datadoc;
TString _codpag, _descr, _numdoc;
protected: protected:
static bool annopart_handler(TMask_field& f, KEY k); static bool annopart_handler(TMask_field& f, KEY k);
static bool numpart_handler(TMask_field& f, KEY k); static bool numpart_handler(TMask_field& f, KEY k);
static bool partite_notify(TSheet_field& partite, int r, KEY k); static bool partite_notify(TSheet_field& partite, int r, KEY k);
static bool scadenze_notify(TSheet_field& partite, int r, KEY k);
static bool show_all_handler(TMask_field& f, KEY k); static bool show_all_handler(TMask_field& f, KEY k);
static bool edit_scadenza_handler(TMask_field& f, KEY k); static bool edit_scadenza_handler(TMask_field& f, KEY k);
static bool nuovo_handler(TMask_field& f, KEY k); static bool nuovo_handler(TMask_field& f, KEY k);
static bool cambio_handler(TMask_field& f, KEY k); static bool cambio_handler(TMask_field& f, KEY k);
static void add_importo(TToken_string& s, const TImporto& i, int dec = 0); static void add_importo(TToken_string& s, const TImporto& i, bool val = FALSE, int pos = -1);
TImporto get_importo(TToken_string& s, int pos) const; TImporto get_importo(TToken_string& s, int pos) const;
void fill_partite(int anno = 0, const char* numero = ""); void fill_partite(int anno = 0, const char* numero = "");
@ -186,8 +194,12 @@ protected:
int update_partita(const TPartita& game, int prow); int update_partita(const TPartita& game, int prow);
void update_saldo_clifo(); void update_saldo_clifo();
int nuova_riga(TPartita& partita) const;
int nuovo_pagamento(TPartita& partita, int nriga, int rata) const; int nuovo_pagamento(TPartita& partita, int nriga, int rata) const;
bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) const; bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) const;
#ifdef __EXTRA__
bool edit_fattura(TPartita& p, int nriga);
#endif
bool cerca_valuta(TValuta& val) const; bool cerca_valuta(TValuta& val) const;
void aggiorna_valuta(const TValuta& val); void aggiorna_valuta(const TValuta& val);
@ -197,12 +209,16 @@ public:
TSheet_field& scadenze() const { return (TSheet_field&)field(P_SCADENZE); } TSheet_field& scadenze() const { return (TSheet_field&)field(P_SCADENZE); }
const TBill& conto() const { return _conto; } const TBill& conto() const { return _conto; }
bool changed() const { return _changed; }
TGame_mask(const TBill& bill, long numreg, int riga); TGame_mask(const TBill& bill, long numreg, int riga);
virtual ~TGame_mask() {} virtual ~TGame_mask() {}
}; };
TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga) TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga)
: TMask("cg2100p"), _conto(bill), _numreg(numreg), _numrig(riga) : TMask("cg2100p"), _conto(bill), _numreg(numreg), _numrig(riga),
_changed(FALSE)
{ {
const char tipocf[2] = { _conto.tipo(), '\0' }; const char tipocf[2] = { _conto.tipo(), '\0' };
set(P_TIPOC, tipocf); set(P_TIPOC, tipocf);
@ -227,6 +243,7 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga)
set_handler(P_CAMBIO, cambio_handler); set_handler(P_CAMBIO, cambio_handler);
partite().set_notify(partite_notify); partite().set_notify(partite_notify);
scadenze().set_notify(scadenze_notify);
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler); scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
} }
@ -302,7 +319,7 @@ bool TGame_mask::cambio_handler(TMask_field& f, KEY k)
real TGame_mask::aggiorna_residuo() real TGame_mask::aggiorna_residuo()
{ {
#ifdef EXTRA #ifdef __EXTRA__
return ZERO; return ZERO;
#else #else
_importo = app().get_cgs_imp(_numrig-1); _importo = app().get_cgs_imp(_numrig-1);
@ -361,7 +378,7 @@ void TGame_mask::aggiorna_valuta(const TValuta& val)
val.val2lit(imp); val.val2lit(imp);
pag.put(PAGSCA_IMPORTO, imp); // Converte in lire l'importo in valuta pag.put(PAGSCA_IMPORTO, imp); // Converte in lire l'importo in valuta
#ifdef __EXTRA__ #ifdef __EXTRA__
game->modifica_pagamento(pag, val); game->modifica_pagamento(pag);
#else #else
app().notify_edit_pagamento(*game, pag, val); app().notify_edit_pagamento(*game, pag, val);
#endif #endif
@ -371,13 +388,10 @@ void TGame_mask::aggiorna_valuta(const TValuta& val)
} }
} }
#ifndef __EXTRA__
if (annorif != 0) if (annorif != 0)
{ {
#ifdef __EXTRA__
const bool proponi = RUE;
#else
const bool proponi = app().causale().tipomov() == 2; const bool proponi = app().causale().tipomov() == 2;
#endif
if (proponi) if (proponi)
{ {
const TMask& cm = app().curr_mask(); const TMask& cm = app().curr_mask();
@ -389,14 +403,16 @@ void TGame_mask::aggiorna_valuta(const TValuta& val)
} }
} }
} }
#endif
fill_partite(annorif, numrif); fill_partite(annorif, numrif);
} }
bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
{ {
TGame_mask& gm = (TGame_mask&)partite.mask();
if (k == K_TAB) if (k == K_TAB)
{ {
TGame_mask& gm = (TGame_mask&)partite.mask();
gm._riga_partite = r; gm._riga_partite = r;
TString_array& scadenze = gm.scadenze().rows_array(); TString_array& scadenze = gm.scadenze().rows_array();
@ -415,6 +431,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
game = new TPartita(zio, anno, num); // ... creane una temporanea game = new TPartita(zio, anno, num); // ... creane una temporanea
TImporto tot_lit, tot_val; TImporto tot_lit, tot_val;
TToken_string riga_fattura;
const int lastrow = game->last(); const int lastrow = game->last();
for (int ri = game->first(); ri <= lastrow; ri = game->succ(ri)) for (int ri = game->first(); ri <= lastrow; ri = game->succ(ri))
@ -422,25 +439,35 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
const TRiga_partite& riga = game->riga(ri); const TRiga_partite& riga = game->riga(ri);
const bool in_valuta = riga.in_valuta(); const bool in_valuta = riga.in_valuta();
if (riga.rate() != 0)
{
riga_fattura.add(ri);
riga_fattura.add("");
riga_fattura.add("");
riga_fattura.add(riga.get(PART_DATADOC));
riga_fattura.add(riga.get(PART_DESCR));
add_importo(riga_fattura, TImporto(riga.sezione(), riga.get_real(SCAD_IMPORTO)));
if (in_valuta)
add_importo(riga_fattura, TImporto(riga.sezione(), riga.get_real(SCAD_IMPORTOVAL)), TRUE);
else
riga_fattura.add("");
riga_fattura.add(riga.get(PART_NREG));
riga_fattura.add(riga.get(PART_DATAREG));
riga_fattura.add(riga.get(PART_NUMDOC));
riga_fattura.add(riga.get(PART_PROTIVA));
scadenze.add(riga_fattura);
}
for (int ra = 1; ra <= riga.rate(); ra++) for (int ra = 1; ra <= riga.rate(); ra++)
{ {
const TRiga_scadenze& scad = riga.rata(ra); const TRiga_scadenze& scad = riga.rata(ra);
TToken_string& row = scadenze.row(scadenze.add("")); TToken_string& row = scadenze.row(scadenze.add(riga_fattura));
row.add(ri); row.add(ra, 1);
row.add(ra); row.add(scad.get(SCAD_DATASCAD), 2);
row.add(scad.get(SCAD_DATASCAD)); add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTO)), FALSE, 5);
row.add(riga.get(PART_DATADOC));
row.add(riga.get(PART_DESCR));
add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTO)));
if (in_valuta) if (in_valuta)
add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTOVAL)), 2); add_importo(row, TImporto(riga.sezione(), scad.get_real(SCAD_IMPORTOVAL)), TRUE, 6);
else
row.add("");
row.add(riga.get(PART_NREG));
row.add(riga.get(PART_DATAREG));
row.add(riga.get(PART_NUMDOC));
row.add(riga.get(PART_PROTIVA));
const int lastp = scad.last(); const int lastp = scad.last();
for (int pa = scad.first(); pa <= lastp; pa = scad.succ(pa)) for (int pa = scad.first(); pa <= lastp; pa = scad.succ(pa))
@ -479,7 +506,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
} }
else else
{ {
add_importo(rabb, abb, 2); add_importo(rabb, abb, TRUE);
rabb.add(""); rabb.add("");
} }
} }
@ -508,7 +535,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
{ {
sl = scad.residuo(TRUE, 0x3); sl = scad.residuo(TRUE, 0x3);
sl.normalize(); sl.normalize();
add_importo(rsal, sl, 2); add_importo(rsal, sl, TRUE);
tot_val += sl; tot_val += sl;
} }
} }
@ -523,7 +550,9 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
TImporto imp(sum.sezione(), ZERO); TImporto imp(sum.sezione(), ZERO);
TToken_string& row = scadenze.row(scadenze.add("")); TToken_string& row = scadenze.row(scadenze.add(""));
row.add("9999|9999| "); row.add(pag.get(PAGSCA_NRIGA));
row.add(pag.get(PAGSCA_NRATA));
row.add("");
row.add(sum.get(PART_DATADOC)); row.add(sum.get(PART_DATADOC));
row.add(sum.get(PART_DESCR)); row.add(sum.get(PART_DESCR));
TImporto i(sum.sezione(), pag.get_real(PAGSCA_IMPORTO)); TImporto i(sum.sezione(), pag.get_real(PAGSCA_IMPORTO));
@ -535,7 +564,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
i = TImporto(sum.sezione(), pag.get_real(PAGSCA_IMPORTOVAL)); i = TImporto(sum.sezione(), pag.get_real(PAGSCA_IMPORTOVAL));
tot_val += i; tot_val += i;
i.normalize(); i.normalize();
add_importo(row, i, 2); add_importo(row, i, TRUE);
} }
else else
row.add(""); row.add("");
@ -552,82 +581,117 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
TToken_string& sp = scadenze.row(scadenze.add("")); TToken_string& sp = scadenze.row(scadenze.add(""));
sp.add("Saldo ", 4); sp << anno << ' ' << num; sp.add("Saldo ", 4); sp << anno << ' ' << num;
add_importo(sp, tot_lit.normalize()); add_importo(sp, tot_lit.normalize());
add_importo(sp, tot_val.normalize(), 2); add_importo(sp, tot_val.normalize(), TRUE);
} }
gm.scadenze().force_update(); gm.scadenze().force_update();
if (should_delete_game) if (should_delete_game)
delete game; delete game;
} }
if (k == K_INS)
{
gm.send_key(K_CTRL + 'N', 0, &partite); // Simula la pressione del tasto nuovo
return FALSE; // Rifiuta l'aggiunta di una riga
}
return TRUE; return TRUE;
} }
bool TGame_mask::scadenze_notify(TSheet_field& scadenze, int r, KEY k)
{
if (k == K_INS)
{
TGame_mask& gm = (TGame_mask&)scadenze.mask();
gm.send_key(K_CTRL + 'N', 0, &scadenze); // Simula la pressione del tasto nuovo
return FALSE; // Rifiuta l'aggiunta di una riga
}
return TRUE;
}
int TGame_mask::nuova_riga(TPartita& partita) const
{
TRiga_partite& part = partita.new_row(); // Creazione nuova riga vuota
const int nriga = part.get_int(PART_NRIGA);
// Copia dati movimento corrente
part.put(PART_NREG, _numreg); // Numero operazione
part.put(PART_NUMRIG, _numrig); // Riga su cui ho cliccato
const real cambio(get(P_CAMBIO));
part.put(PART_CAMBIO, cambio);
part.put(PART_CODVAL, get(P_VALUTA));
part.put(PART_DATACAM, get(P_DATACAMBIO));
#ifdef __EXTRA__
part.put(PART_TIPOMOV, _tipomov);
part.put(PART_DESCR, _descr);
part.put(PART_NUMDOC, _numdoc);
part.put(PART_DATADOC, _datadoc);
part.put(PART_DATAREG, TDate(TODAY));
part.put(PART_SEZ, _sezione);
part.put(PART_SEZABB, _sezione);
part.put(PART_SEZDIFCAM,_sezione);
if (_tipomov == 1)
{
part.put(PART_IMPORTO, _importo.valore());
if (!cambio.is_zero())
{
real impval = _importo.valore();
impval /= cambio;
impval.round(2);
part.put(PART_IMPORTOVAL, impval);
}
}
#else
TMask& cm = app().curr_mask();
const TCausale& causale = app().causale();
const int tipomov = causale.tipomov();
part.put(PART_TIPOMOV, tipomov);
part.put(PART_DESCR, cm.get(F_DESCR));
part.put(PART_NUMDOC, cm.get(F_NUMDOC));
part.put(PART_DATADOC, cm.get(F_DATADOC));
part.put(PART_DATAREG, cm.get(F_DATAREG));
// Copia dati causale corrente
part.put(PART_CODCAUS, causale.codice());
if (causale.iva() != nessuna_iva)
{
part.put(PART_REG, cm.get(F_CODREG));
part.put(PART_PROTIVA, cm.get(F_PROTIVA));
}
const char tipoc = conto().tipo();
// Complesso algoritmo per calcolare la sezione di una nuova riga partita
char sezione = causale.sezione(1); // Usa la sezione della causale
if (sezione <= ' ') // Se non c'e' la sezione bell'e' ch'e' pronta
{
if (tipomov == 1 || tipomov == 5) // calcola in base al tipo movimento e
sezione = (tipoc == 'C') ? 'D' : 'A'; // al tipo cliente/fornitore
else
sezione = (tipoc == 'C') ? 'A' : 'D';
}
if (tipoc > ' ') // Se il tipo e' C o F
{
TBill bill; causale.bill(1, bill); // Legge primo conto causale
if (bill.tipo() != tipoc)
sezione = (sezione == 'D') ? 'A' : 'D'; // scambia segno
}
// Memorizza solo la sezione (importi nulli)
part.put(PART_SEZ, sezione);
part.put(PART_SEZABB, sezione);
part.put(PART_SEZDIFCAM, sezione);
#endif
return nriga;
}
int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const
{ {
const TBill& conto = partita.conto(); // Legge conto principale const TBill& conto = partita.conto(); // Legge conto principale
int nrigp = partita.mov2rig(_numreg, _numrig); // Cerca riga partita relativa alla riga rmov int nrigp = partita.mov2rig(_numreg, _numrig); // Cerca riga partita relativa alla riga rmov
TMask& cm = app().curr_mask();
#ifndef __EXTRA__
const TCausale& causale = app().causale();
#endif
if (nrigp <= 0) // Devo creare una nuova riga di partita if (nrigp <= 0) // Devo creare una nuova riga di partita
{ nrigp = nuova_riga(partita);
TRiga_partite& part = partita.new_row(); // Creazione nuova riga vuota
nrigp = part.get_int(PART_NRIGA);
// Copia dati movimento corrente
part.put(PART_NREG, _numreg); // Numero operazione
part.put(PART_NUMRIG, _numrig); // Riga su cui ho cliccato
part.put(PART_DATADOC, cm.get(F_DATADOC));
part.put(PART_DESCR, cm.get(F_DESCR));
part.put(PART_CODVAL, get(P_VALUTA));
part.put(PART_CAMBIO, get(P_CAMBIO));
part.put(PART_DATACAM, get(P_DATACAMBIO));
#ifdef __EXTRA__
part.zero(PART_DATAREG);
part.zero(PART_NUMDOC);
// Complesso algoritmo per calcolare la sezione di una nuova riga partita
const char sezione = (conto.tipo() == 'C') ? 'A' : 'D';
#else
part.put(PART_DATAREG, cm.get(F_DATAREG));
part.put(PART_NUMDOC, cm.get(F_NUMDOC));
// Copia dati causale corrente
const int tipomov = causale.tipomov();
part.put(PART_TIPOMOV, tipomov);
part.put(PART_CODCAUS, causale.codice());
if (causale.iva() != nessuna_iva)
{
part.put(PART_REG, cm.get(F_CODREG));
part.put(PART_PROTIVA, cm.get(F_PROTIVA));
}
// Complesso algoritmo per calcolare la sezione di una nuova riga partita
char sezione = causale.sezione(1); // Usa la sezione della causale
if (sezione <= ' ') // Se non c'e' la sezione bell'e' ch'e' pronta
{
if (tipomov == 1 || tipomov == 5) // calcola in base al tipo movimento e
sezione = (conto.tipo() == 'C') ? 'D' : 'A'; // al tipo cliente/fornitore
else
sezione = (conto.tipo() == 'C') ? 'A' : 'D';
}
if (conto.tipo() > ' ') // Se il tipo e' C o F
{
TBill bill; causale.bill(1, bill); // Legge primo conto causale
if (bill.tipo() != conto.tipo())
sezione = (sezione == 'D') ? 'A' : 'D'; // scambia segno
}
#endif
part.put(PART_SEZ, sezione); // Memorizza solo la sezione (importi nulli)
part.put(PART_SEZABB, sezione);
part.put(PART_SEZDIFCAM, sezione);
}
TRectype& pagamento = partita.pagamento(nriga, rata, nrigp); // Crea nuovo pagamento TRectype& pagamento = partita.pagamento(nriga, rata, nrigp); // Crea nuovo pagamento
@ -662,10 +726,11 @@ int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const
pagamento.put(PAGSCA_CODABI, scad.get(SCAD_CODABI)); pagamento.put(PAGSCA_CODABI, scad.get(SCAD_CODABI));
pagamento.put(PAGSCA_CODCAB, scad.get(SCAD_CODCAB)); pagamento.put(PAGSCA_CODCAB, scad.get(SCAD_CODCAB));
pagamento.put(PAGSCA_CODAG, scad.get(SCAD_CODAG)); pagamento.put(PAGSCA_CODAG, scad.get(SCAD_CODAG));
pagamento.put(PAGSCA_DATAPAG, cm.get(F_DATADOC)); pagamento.put(PAGSCA_DATAPAG, _datadoc);
} }
#ifndef __EXTRA__ #ifndef __EXTRA__
const TCausale& causale = app().causale();
TBill contro; causale.bill(caus, contro); // Legge conto contropartita TBill contro; causale.bill(caus, contro); // Legge conto contropartita
if (caus != 2 && contro.empty()) // Se non specificato ... if (caus != 2 && contro.empty()) // Se non specificato ...
causale.bill(caus = 2, contro); // ... prende il primo causale.bill(caus = 2, contro); // ... prende il primo
@ -675,14 +740,15 @@ int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const
return nrigp; return nrigp;
} }
bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TMask& m = f.mask(); TMask& m = f.mask();
const int nriga = m.get_int(101); const int nriga = m.get_int(101);
const int nrata = m.get_int(102);
if (nriga == 0 || nrata == 0) if (nriga == 0)
return FALSE; // Ho cliccato su di un saldo (per sbaglio!) return FALSE; // Ho cliccato su di un saldo (per sbaglio!)
TGame_mask& gm = (TGame_mask&)(m.get_sheet()->mask()); TGame_mask& gm = (TGame_mask&)(m.get_sheet()->mask());
@ -696,23 +762,67 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
TPartita& game = app().partite().partita(bill, anno, numero); TPartita& game = app().partite().partita(bill, anno, numero);
int nrigp = m.get_int(112); const int nrata = m.get_int(102); // Rata selezionata (puo' essere 0)
if (nrigp == 0) int nrigp = m.get_int(112); // Pagamento selezionato (puo' essere 0)
{ if (nrata != 0 && nrigp == 0)
nrigp = gm.nuovo_pagamento(game, nriga, nrata); nrigp = gm.nuovo_pagamento(game, nriga, nrata);
if (nrigp > 0) // Si vuole editare un pagamento
{
const bool dirty = gm.edit_pagamento(game, nriga, nrata, nrigp);
if (dirty)
{
gm.update_partita(game, gm._riga_partite);
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
gm._changed = TRUE;
if (!game.esiste(nriga, nrata, nrigp))
m.stop_run(K_ESC);
}
} }
else else
{ { // Si vogliono editare le rate
const long nreg = m.get_long(108); const long nreg = m.get_long(108);
if (nreg != gm._numreg) #ifdef __EXTRA__
return f.error_box("Modificare il movimento %ld", nreg); if (nreg > 0)
} {
bool can_run = TRUE;
if (gm._changed)
{
can_run = yesno_box("Salvare le parite modificate?");
if (can_run)
{
app().partite().rewrite();
gm._changed = FALSE; // Resetta flag di cambiato
}
}
if (can_run)
{
const char* pn = "cg2 -0";
TExternal_app prima_nota(pn);
TString16 numreg; numreg << "1|" << nreg;
TMessage msg(pn, MSG_LN, numreg);
msg.send(); // Messaggio di collegamento al movimento nreg
app().partite().destroy(); // Distrugge tutte le partite in memoria
prima_nota.run(); // Lancia la prima nota
const bool dirty = gm.edit_pagamento(game, nriga, nrata, nrigp); const int anno = gm.get_int(P_ANNO);
if (dirty) const TString16 numero = gm.get(P_NUMERO);
{ gm.fill_partite(anno, numero); // Ripristina partite
gm.update_partita(game, gm._riga_partite); }
partite_notify(gm.partite(), gm._riga_partite, K_TAB); }
else
gm.edit_fattura(game, nriga);
#else
if (nreg != gm._numreg || nrata == 0)
{
if (nreg == 0)
f.error_box("Utilizzare la gestione extra-contabile");
else
f.error_box("Modificare il movimento %ld", nreg);
return FALSE;
}
#endif
} }
} }
return TRUE; return TRUE;
@ -723,47 +833,71 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TGame_mask& gm = (TGame_mask&)f.mask();
int anno; int anno;
TString16 numero; TString numero;
// Graffa tattica per distruggere la maschera new_game alla fine del blocco // Graffa tattica per distruggere la maschera new_game alla fine del blocco
{ {
TMask new_game("Nuova partita", 1, 24, 5); TMask new_game("cg2100n");
new_game.add_number(P_ANNO, 0, "Anno ", 1, 1, 4, "A");
new_game.add_string(P_NUMERO, 0, "Partita ", 1, 2, 7, "U");
new_game.add_button(DLG_OK, 0, "" , -12, 3, 8, 2);
new_game.add_button(DLG_CANCEL, 0, "" , -22, 3, 8, 2);
new_game.first_focus(P_NUMERO); new_game.first_focus(P_NUMERO);
#ifdef __EXTRA__ #ifndef __EXTRA__
const bool proponi = TRUE; const TMask& cm = app().curr_mask();
#else new_game.disable(-1);
const bool proponi = app().causale().tipomov() == 2; gm._tipomov = app().causale().tipomov();
#endif new_game.set(P_NUOVO, gm._tipomov);
if (proponi) new_game.set(P_SEZIONE, gm._importo.sezione());
new_game.set(P_RESIDUO, gm._importo.valore());
new_game.set(P_DATADOC, cm.get(F_DATADOC));
new_game.set(P_NUMDOC, cm.get(F_NUMDOC));
new_game.set(P_DESCR, cm.get(F_DESCR));
if (gm._tipomov < 3)
new_game.set(P_CODPAG,cm.get(F_CODPAG));
if (gm._tipomov == 2)
{ {
const TMask& cm = app().curr_mask();
new_game.set(P_ANNO, cm.get(F_ANNORIF)); new_game.set(P_ANNO, cm.get(F_ANNORIF));
new_game.set(P_NUMERO, cm.get(F_NUMRIF)); new_game.set(P_NUMERO, cm.get(F_NUMRIF));
} }
#endif
k = new_game.run(); k = new_game.run();
anno = new_game.get_int(P_ANNO); anno = new_game.get_int(P_ANNO);
numero = new_game.get(P_NUMERO); numero = new_game.get(P_NUMERO);
gm._tipomov = new_game.get_int(P_NUOVO);
gm._codpag = new_game.get(P_CODPAG);
gm._sezione = new_game.get(P_SEZIONE)[0];
gm._importo.set(gm._sezione, real(new_game.get(P_RESIDUO)));
gm._numdoc = new_game.get(P_NUMDOC);
gm._datadoc = new_game.get(P_DATADOC);
gm._descr = new_game.get(P_DESCR);
} }
if (k == K_ENTER) if (k == K_ENTER)
{ {
TGame_mask& gm = (TGame_mask&)f.mask();
TPartita& game = app().partite().partita(gm.conto(), anno, numero); TPartita& game = app().partite().partita(gm.conto(), anno, numero);
if (game.ok()) if (game.ok())
return error_box("La partita %d %s esiste gia'.", anno, (const char*)numero); return error_box("La partita %d %s esiste gia'.", anno, (const char*)numero);
const int nriga = TPartita::UNASSIGNED; if (gm._tipomov > 1)
const int nrata = TPartita::UNASSIGNED; {
const int nrigp = gm.nuovo_pagamento(game, nriga, nrata); const int nriga = TPartita::UNASSIGNED;
gm.edit_pagamento(game, nriga, nrata, nrigp); const int nrata = TPartita::UNASSIGNED;
const int nrigp = gm.nuovo_pagamento(game, nriga, nrata);
gm.edit_pagamento(game, nriga, nrata, nrigp);
}
#ifdef __EXTRA__
else
{
gm.edit_fattura(game, 0);
}
#endif
if (game.ok()) if (game.ok())
{
gm.fill_partite(anno, numero); // Aggiorna sheet partite gm.fill_partite(anno, numero); // Aggiorna sheet partite
gm._changed = TRUE;
}
else else
app().partite().destroy(gm.conto(), anno, numero); app().partite().destroy(gm.conto(), anno, numero);
} }
@ -777,14 +911,15 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
// Metodi della maschera delle partite // Metodi della maschera delle partite
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
void TGame_mask::add_importo(TToken_string& s, const TImporto& i, int dec) void TGame_mask::add_importo(TToken_string& s, const TImporto& i, bool valuta, int pos)
{ {
if (i.is_zero()) if (i.is_zero())
s.add(""); s.add("", pos);
else else
{ {
s.add(i.valore().string(dec)); TString80 v;
s << ' ' << i.sezione(); v << i.valore().string(valuta ? 2 : 0) << ' ' << i.sezione();
s.add(v, pos);
} }
} }
@ -867,16 +1002,17 @@ void TGame_mask::update_saldo_clifo()
r.add(""); r.add("");
r.add(TDate(TODAY).string()); r.add(TDate(TODAY).string());
r.add(""); r.add("");
add_importo(r, sal); add_importo(r, sal.normalize());
add_importo(r, doc); add_importo(r, doc.normalize());
add_importo(r, pag); add_importo(r, pag.normalize());
add_importo(r, imp); add_importo(r, imp.normalize());
r.add("Saldo "); r.add("Saldo ");
if (get(P_TIPOC)[0] == 'C') if (get(P_TIPOC)[0] == 'C')
r << "cliente"; r << "cliente";
else else
r << "fornitore"; r << "fornitore";
r << conto().sottoconto();
} }
void TGame_mask::fill_partite(int annorif, const char* numrif) void TGame_mask::fill_partite(int annorif, const char* numrif)
@ -954,13 +1090,7 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co
TPay_mask m; TPay_mask m;
// Dati della scadenza che ha generato la partita if (nriga == TPartita::UNASSIGNED)
if (nriga != TPartita::UNASSIGNED)
{
const TRiga_scadenze& scaden = p.rata(nriga, nrata);
m.set_pag(oldpag, scaden, _importo);
}
else
{ {
nriga = p.primo_pagamento(); nriga = p.primo_pagamento();
TRiga_partite& riga = p.riga(nriga); TRiga_partite& riga = p.riga(nriga);
@ -968,6 +1098,11 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co
m.set_pag(oldpag, scaden, _importo); m.set_pag(oldpag, scaden, _importo);
riga.destroy_rows(); riga.destroy_rows();
} }
else
{
const TRiga_scadenze& scaden = p.rata(nriga, nrata);
m.set_pag(oldpag, scaden, _importo);
}
m.set(S_DESCAGG, somma.get(PART_DESCR)); m.set(S_DESCAGG, somma.get(PART_DESCR));
const KEY key = m.run(); const KEY key = m.run();
@ -988,7 +1123,7 @@ else
const TValuta val; // Non cambiare valuta! const TValuta val; // Non cambiare valuta!
#ifdef __EXTRA__ #ifdef __EXTRA__
p.modifica_pagamento(newpag, val); p.modifica_pagamento(newpag);
#else #else
app().notify_edit_pagamento(p, newpag, val); app().notify_edit_pagamento(p, newpag, val);
#endif #endif
@ -997,6 +1132,8 @@ else
return key != K_ESC; return key != K_ESC;
} }
#ifndef __EXTRA__
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Edit delle partite // Edit delle partite
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -1019,10 +1156,14 @@ bool TPrimanota_application::edit_partite(const TMask& m, int riga)
// Esecuzione maschera di selezione partite // Esecuzione maschera di selezione partite
TGame_mask mask(b, mov.get_long(MOV_NUMREG), riga+1); TGame_mask mask(b, mov.get_long(MOV_NUMREG), riga+1);
mask.run(); mask.run();
cgs().force_update(); // Aggiornamento righe contabili
calcola_saldo();
return TRUE; const bool changed = mask.changed();
if (changed)
{
cgs().force_update(); // Aggiornamento righe contabili
calcola_saldo();
}
return changed;
} }
#endif

View File

@ -421,17 +421,28 @@ void TPagamento::set_imprata(int i, const real& r)
void TPagamento::set_percrata(int i, real r) void TPagamento::set_percrata(int i, real r)
{ {
TToken_string& tt = (TToken_string&)_rate[i]; TToken_string& tt = (TToken_string&)_rate[i];
TDate d = _inizio;
tt.add(r.string(), 1); tt.add(r.string(), 1);
} }
real TPagamento::recalc_percrata(int i)
{
real hm(_tpr < 4 ? _firstr : _secndr);
if (i == 0 && _tpr > 0 && _tpr < 4)
hm -= _secndr;
real perc = tpay_rata(i) * 100.0 / hm;
perc.round(2);
set_percrata(i, perc);
return perc;
}
TToken_string& TPagamento::set_rata(int index, const real& howmuch, const real& quanto, TToken_string& TPagamento::set_rata(int index, const real& howmuch, const real& quanto,
const TDate& date, int type,const char* ulc, bool pagato) const TDate& date, int type,const char* ulc, bool pagato)
{ {
// calcola percentuali e scadenze a partire dagli importi // calcola percentuali e scadenze a partire dagli importi
TToken_string* tt = (TToken_string*)_rate.objptr(index); TToken_string* tt = (TToken_string*)_rate.objptr(index);
int first = _tpr < 4 ? 0 : 1; const int first = _tpr < 4 ? 0 : 1;
const bool nwr = (tt == NULL); // nuova rata const bool nwr = (tt == NULL); // nuova rata
@ -483,45 +494,36 @@ word TPagamento::validate() const
int first = _tpr < 4 ? 0 : 1; int first = _tpr < 4 ? 0 : 1;
real toshare(_tpr < 4 ? _firstr : _secndr); real toshare(_tpr < 4 ? _firstr : _secndr);
// TDistrib ds(toshare,0);
// check percentages & prepare slicer // check percentages & prepare slicer
for (int i = first; i < n_rate(); i++) for (int i = first; i < n_rate(); i++)
{ r += perc_rata(i);
real p(perc_rata(i)); r.round(1);
// ds.add(p);
r += p;
}
if (r != real(100.0)) if (r != real(100.0))
res |= P_RSUM; res |= P_RSUM;
if (_inited) if (_inited)
{
// RIMOSSO in quanto con rate uguali non si usa la percentuale,
// per evitare merdaglia
// ds.init(toshare);
// check importi rate consistenti con la percentuale
// for (int i = first; i < n_rate(); i++)
// {
// real r1(tpay_rata(i));
// real r2(ds.get());
// if (r1 != r2)
// { res |= P_IMPNC; break; }
// }
// check errori date scadenze (se istanziate)
TDate d(data_rata(0));
if (d < _inizio)
res |= P_INIZIO;
for (i = 1; i < n_rate(); i++)
{ {
if (data_rata(i) <= d) real tot;
{ res |= P_SCAD; break; } for (int i = first; i < n_rate(); i++)
d = data_rata(i); tot += tpay_rata(i);
}
if (tot != _firstr+_secndr)
res |= P_TOTNC;
// check errori date scadenze (se istanziate)
TDate d(data_rata(0));
if (d < _inizio)
res |= P_INIZIO;
for (i = 1; i < n_rate(); i++)
{
if (data_rata(i) <= d)
{ res |= P_SCAD; break; }
d = data_rata(i);
} }
}
return res; return res;
} }
@ -541,6 +543,8 @@ void TPagamento::strerr(word err, TString& s)
s << "\n L'importo dato e' inferiore al minimo possibile"; s << "\n L'importo dato e' inferiore al minimo possibile";
if (err & P_TROP) if (err & P_TROP)
s << "\n L'importo dato e' superiore al massimo possibile"; s << "\n L'importo dato e' superiore al massimo possibile";
if (err & P_TOTNC)
s << "\n La somma degli importi e' diversa dal totale del pagamento";
} }
const char* TPagamento::desc_tpr() const const char* TPagamento::desc_tpr() const
@ -572,7 +576,7 @@ const char* TPagamento::desc_tipo(int i) const
case 5: o = "Paghero'"; break; case 5: o = "Paghero'"; break;
case 6: o = "Lettera di credito"; break; case 6: o = "Lettera di credito"; break;
case 7: o = "Tratta accettata"; break; case 7: o = "Tratta accettata"; break;
case 8: o = "Rapporti interb. diretti"; break; case 8: o = "Rapporti interban. diretti"; break;
case 9: o = "Bonifici"; break; case 9: o = "Bonifici"; break;
default: o = "Altro pagamento"; break; default: o = "Altro pagamento"; break;
} }
@ -1022,14 +1026,15 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified,
} }
else // i != row modified else // i != row modified
{ {
if (rdiff == 2) continue; if (rdiff == 2)
continue;
if (i > 0 && !((perc_rata(i-1) == perc_rata(i)))) if (i > 0 && !((perc_rata(i-1) == perc_rata(i))))
{ {
if (rdiff == 2) if (rdiff == 2)
rdiff = 1; rdiff = 1;
_rdiff = TRUE; _rdiff = FALSE;
} }
if (is_perc_modified) if (is_perc_modified)
rsum += perc_rata(i); rsum += perc_rata(i);
else else
@ -1278,16 +1283,15 @@ void TPagamento::set_total(const real& imponibile, const real& imposta, const re
break; break;
} }
real toslice = _tpr > 1 ? _secndr : _firstr; const real toslice = _tpr > 1 ? _secndr : _firstr;
_slicer.init(toslice, TRUE); _slicer.init(toslice, TRUE);
for (int i = 0; i < _rate.items(); i++) for (int i = 0; i < _rate.items(); i++)
{ {
TToken_string& t = (TToken_string&)_rate[i]; TToken_string& t = (TToken_string&)_rate[i];
real rr(t.get(1)); const real rr(t.get(1));
_slicer.add(rr); _slicer.add(rr);
} }
} }
@ -1319,9 +1323,6 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
// 6,7,8,9 - Banche // 6,7,8,9 - Banche
const bool paid = ratapagata(i); const bool paid = ratapagata(i);
ts.add(paid ? "X" : "", 10); // 10 - Pagaya ts.add(paid ? "X" : "", 10); // 10 - Pagaya
sf.enable_cell(i,1,!paid); // importo
sf.enable_cell(i,2,!paid); // in valuta
sf.enable_cell(i,3,!paid); // percentuale
} }
// destroy remaining // destroy remaining

View File

@ -21,6 +21,7 @@ const word P_SCAD = 0x0004; // scadenze non consecutive
const word P_INIZIO = 0x0008; // data 1a rata < data inizio pagamenti const word P_INIZIO = 0x0008; // data 1a rata < data inizio pagamenti
const word P_NEG = 0x0010; // importo specificato < minimo possibile const word P_NEG = 0x0010; // importo specificato < minimo possibile
const word P_TROP = 0x0020; // importo specificato > massimo possibile const word P_TROP = 0x0020; // importo specificato > massimo possibile
const word P_TOTNC = 0x0040; // totale importi != totale pagamento
class TPagamento : public TObject class TPagamento : public TObject
{ {
@ -98,6 +99,7 @@ public:
void set_rate_differenziate(int v); void set_rate_differenziate(int v);
void set_tipo_prima_rata(int v, int sscad = -1); void set_tipo_prima_rata(int v, int sscad = -1);
void set_percrata(int n, real r); void set_percrata(int n, real r);
real recalc_percrata(int i);
void set_numero_rate(int n, int sscad = -1, int rdiff = 1); void set_numero_rate(int n, int sscad = -1, int rdiff = 1);
void set_inizio_scadenza(char v) { _inscad = v; } void set_inizio_scadenza(char v) { _inscad = v; }

View File

@ -318,35 +318,52 @@ TImporto TRiga_scadenze::importo_da_pagare(bool val) const
// Calcola l'abbuono in valuta della rata e ritorna il suo tipo: // Calcola l'abbuono in valuta della rata e ritorna il suo tipo:
// 'A' abbuono attivo; 'P' abbuono passivo // 'A' abbuono attivo; 'P' abbuono passivo
// La sezione dell'abbuono calcolato e' quella della riga contabile in cui finira' char TRiga_scadenze::calcola_abbuono(int p, TImporto& abbuono, bool update)
char TRiga_scadenze::calcola_abbuono(int p, TImporto& abbuono) const
{ {
bool ap = ' '; char ap = ' ';
TRectype& pag = row(p);
const TRectype& pag = row(p); const char sez = partita().riga(p).sezione();
if (pag.get_char(PAGSCA_ACCSAL) == 'S')
if (update)
{ {
abbuono = importo_da_pagare(TRUE); if (pag.get_char(PAGSCA_ACCSAL) == 'S')
abbuono += importo_pagato(TRUE);
for (int r = last(); r > 0; r = pred(r)) if (r != p)
{ {
const TRiga_partite& sum = partita().riga(r); // Riga partite abbuono = importo_da_pagare(TRUE);
const TImporto imp(sum.sezione(), row(r).get_real(PAGSCA_ABBUONI)); pag.zero(PAGSCA_ABBUONI);
abbuono += imp; abbuono += importo_pagato(TRUE, 0x3); // Conta anche altri abbuoni
abbuono.swap_section();
const int sign = abbuono.valore().sign();
if (sign != 0)
{
if (sign > 0)
ap = abbuono.sezione() == 'D' ? 'A' : 'P';
else
ap = abbuono.sezione() == 'D' ? 'P' : 'A';
}
} }
else
abbuono.valore() = ZERO;
const int sign = abbuono.valore().sign(); if (ap > ' ')
if (sign != 0)
{ {
if (sign > 0) abbuono.normalize(sez);
ap = abbuono.sezione() == 'D' ? 'P' : 'A'; pag.put(PAGSCA_ABBUONI, abbuono.valore());
else pag.put(PAGSCA_PASSATT, ap);
ap = abbuono.sezione() == 'D' ? 'A' : 'P'; }
else
{
pag.zero(PAGSCA_ABBUONI);
pag.zero(PAGSCA_PASSATT);
} }
} }
else else
abbuono.valore() = ZERO; {
abbuono.set(sez, pag.get_real(PAGSCA_ABBUONI));
ap = pag.get_char(PAGSCA_PASSATT);
if (ap < ' ') ap = ' ';
}
return ap; return ap;
} }
@ -364,15 +381,15 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
if (update) if (update)
{ {
diffcam = importo_da_pagare(FALSE); diffcam = importo_da_pagare(FALSE);
diffcam += importo_pagato(FALSE, 0x3); // Conta anche gli abbuoni pag.zero(PAGSCA_DIFFCAM);
diffcam += importo_pagato(FALSE, 0x7); // Conta anche gli abbuoni e le altre diffcam
diffcam.swap_section();
diffcam.normalize(sez); diffcam.normalize(sez);
pag.put(PAGSCA_DIFFCAM, diffcam.valore());
const TImporto gir(sez, -diffcam.valore());
pag.put(PAGSCA_DIFFCAM, gir.valore());
} }
else else
{ {
diffcam.set(sez, -pag.get_real(PAGSCA_DIFFCAM)); diffcam.set(sez, pag.get_real(PAGSCA_DIFFCAM));
} }
} }
else else
@ -381,7 +398,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
pag.zero(PAGSCA_DIFFCAM); pag.zero(PAGSCA_DIFFCAM);
} }
return diffcam.normalize(); return diffcam;
} }
TImporto TRiga_scadenze::residuo(bool val, int mode) const TImporto TRiga_scadenze::residuo(bool val, int mode) const
@ -394,7 +411,8 @@ TImporto TRiga_scadenze::residuo(bool val, int mode) const
bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
char& new_ap, TImporto& new_abb, TImporto& new_diffcam) char& new_ap, TImporto& new_abb, TImporto& new_diffcam,
bool update)
{ {
const bool in_val = in_valuta(); const bool in_val = in_valuta();
const int nrigp = new_pag.get_int(PAGSCA_NRIGP); const int nrigp = new_pag.get_int(PAGSCA_NRIGP);
@ -402,48 +420,35 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta&
TRiga_partite& sum = partita().riga(nrigp); TRiga_partite& sum = partita().riga(nrigp);
TImporto old_abbuono; TImporto old_abbuono;
old_ap = calcola_abbuono(nrigp, old_abbuono); // Vecchio abbuono in valuta old_ap = calcola_abbuono(nrigp, old_abbuono, FALSE); // Vecchio abbuono in valuta
old_abb = old_abbuono; // Vecchio abbuono in lire old_abb = old_abbuono; // Vecchio abbuono in lire
if (in_val) if (in_val)
{ {
old_abb.valore() *= sum.get_real(PART_CAMBIO); old_abb.valore() *= sum.get_real(PART_CAMBIO);
old_abb.valore().round(); old_abb.valore().round();
} }
old_diffcam = calcola_differenza_cambio(nrigp, FALSE); old_diffcam = calcola_differenza_cambio(nrigp, FALSE);
if (in_val && !valuta.in_lire()) if (in_val && !valuta.in_lire())
valuta.put(sum); valuta.put(sum);
row(nrigp) = new_pag; row(nrigp) = new_pag;
row(nrigp).zero(PAGSCA_ABBUONI); // Azzera abbuoni per ricalcolo
row(nrigp).zero(PAGSCA_DIFFCAM); // Azzera differenza cambio per ricalcolo
TImporto new_abbuono; TImporto new_abbuono;
new_ap = calcola_abbuono(nrigp, new_abbuono); // Calcolo abbuono in valuta new_ap = calcola_abbuono(nrigp, new_abbuono, update); // Calcolo abbuono in valuta
new_abb = new_abbuono; // Calcola nuovo abbuono in lire new_abb = new_abbuono; // Calcola nuovo abbuono in lire
if (in_valuta()) if (in_valuta())
{ {
new_abb.valore() *= sum.get_real(PART_CAMBIO); new_abb.valore() *= sum.get_real(PART_CAMBIO);
new_abb.valore().round(); new_abb.valore().round();
} }
new_abb.normalize();
// Scambia sezione per registrazione contabile new_diffcam = calcola_differenza_cambio(nrigp, update);
old_abbuono.swap_section();
new_abbuono.swap_section();
new_abbuono.normalize(sum.sezione());
if (new_ap != ' ')
row(nrigp).put(PAGSCA_ABBUONI, new_abbuono.valore());
else
row(nrigp).zero(PAGSCA_ABBUONI);
sum.update(old_abbuono, new_abbuono, PART_SEZABB, PART_ABBUONI); sum.update(old_abbuono, new_abbuono, PART_SEZABB, PART_ABBUONI);
sum.update(old_diffcam, new_diffcam, PART_SEZDIFCAM, PART_DIFFCAM);
new_diffcam = calcola_differenza_cambio(nrigp, TRUE);
// Memorizza differenza cambi invertita, mettendo new_diffcam prima di old_diffcam!
sum.update(new_diffcam, old_diffcam, PART_SEZDIFCAM, PART_DIFFCAM);
sum.update(old_pag, new_pag, PART_IMPORTO); sum.update(old_pag, new_pag, PART_IMPORTO);
sum.update(old_pag, new_pag, PART_IMPORTOVAL); sum.update(old_pag, new_pag, PART_IMPORTOVAL);
sum.update(old_pag, new_pag, PART_RITENUTE); sum.update(old_pag, new_pag, PART_RITENUTE);
@ -572,7 +577,24 @@ bool TRiga_partite::update(const TImporto& vec, const TImporto& nuo,
return zero; return zero;
} }
int TRiga_partite::rata_con_abbuoni_diffcam() const
{
int found = 0;
for (int s = rate(); s > 0 && found == 0; s--)
{
const TRiga_scadenze& scad = rata(s);
for (int p = scad.last(); p > 0; p = scad.pred(p))
{
const TRectype& pag = scad.row(p);
if (!pag.get_real(PART_ABBUONI).is_zero() || !pag.get_real(PART_DIFFCAM).is_zero())
{
found = s;
break;
}
}
}
return found;
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TPartita // TPartita
@ -679,7 +701,7 @@ TRiga_partite& TPartita::new_row(int r)
TRiga_scadenze& TPartita::rata(int nriga, int nrata) const TRiga_scadenze& TPartita::rata(int nriga, int nrata) const
{ {
if (nriga <= 0) nriga = prima_fattura(); // if (nriga <= 0) nriga = prima_fattura();
const TRiga_partite& r = riga(nriga); const TRiga_partite& r = riga(nriga);
return r.rata(nrata); return r.rata(nrata);
} }
@ -695,6 +717,15 @@ bool TPartita::rata_chiusa(int nriga, int nrata) const
return pag; return pag;
} }
bool TPartita::esistono_abbuoni_diffcam(long nreg) const
{
int nrata = 0;
const int nriga = prima_fattura(nreg);
if (_part.exist(nriga))
nrata = riga(nriga).rata_con_abbuoni_diffcam();
return nrata > 0;
}
TRectype& TPartita::pagamento(int nriga, int nrata, int nrigp) TRectype& TPartita::pagamento(int nriga, int nrata, int nrigp)
{ {
if (nriga == UNASSIGNED) if (nriga == UNASSIGNED)
@ -877,22 +908,10 @@ bool TPartita::utilizzata(int nrigp) const
return _unassigned.exist(nrigp); return _unassigned.exist(nrigp);
} }
bool TPartita::esistono_abbuoni_diffcam() const
{
for (int r = last(); r > 0; r = pred(r))
{
const TRiga_partite& row = riga(r);
if (!row.get_real(PART_ABBUONI).is_zero() || !row.get_real(PART_DIFFCAM).is_zero())
return TRUE;
}
return FALSE;
}
bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
char& new_ap, TImporto& new_abb, TImporto& new_diffcam) char& new_ap, TImporto& new_abb, TImporto& new_diffcam,
bool update)
{ {
const int nriga = new_pag.get_int(PAGSCA_NRIGA); const int nriga = new_pag.get_int(PAGSCA_NRIGA);
const int nrata = new_pag.get_int(PAGSCA_NRATA); const int nrata = new_pag.get_int(PAGSCA_NRATA);
@ -905,7 +924,7 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta
TRiga_scadenze& scaden = rata(nriga, nrata); TRiga_scadenze& scaden = rata(nriga, nrata);
empty = scaden.modifica_pagamento(new_pag, valuta, empty = scaden.modifica_pagamento(new_pag, valuta,
old_ap, old_abb, old_diffcam, old_ap, old_abb, old_diffcam,
new_ap, new_abb, new_diffcam); new_ap, new_abb, new_diffcam, update);
} }
else else
{ {
@ -940,7 +959,7 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag)
TValuta valuta; TValuta valuta;
return modifica_pagamento(new_pag, valuta, return modifica_pagamento(new_pag, valuta,
old_ap, old_abbuono, old_diffcam, old_ap, old_abbuono, old_diffcam,
new_ap, new_abbuono, new_diffcam); new_ap, new_abbuono, new_diffcam, FALSE);
} }
@ -1021,7 +1040,7 @@ void TPartita::sposta_riga(int r, TPartita& part)
int* address = new int[address_size]; int* address = new int[address_size];
memset(address, 0, address_size*sizeof(int)); memset(address, 0, address_size*sizeof(int));
TToken_string knames(256); TToken_string knames(64);
knames.add(PART_TIPOCF); knames.add(PART_TIPOCF);
knames.add(PART_GRUPPO); knames.add(PART_GRUPPO);
knames.add(PART_CONTO); knames.add(PART_CONTO);
@ -1062,11 +1081,9 @@ void TPartita::sposta_riga(int r, TPartita& part)
if (part.esiste(r, i, nrigp)) if (part.esiste(r, i, nrigp))
{ {
npg = part.pagamento(r, i, nrigp); npg = part.pagamento(r, i, nrigp);
CHECK(npg.get_char(PAGSCA_ACCSAL) != 'S', "Can't add to soldered payment");
somma(pag, npg, PART_IMPORTO); somma(pag, npg, PART_IMPORTO);
somma(pag, npg, PART_IMPORTOVAL); somma(pag, npg, PART_IMPORTOVAL);
somma(pag, npg, PART_ABBUONI);
somma(pag, npg, PART_DIFFCAM);
npg.put(PAGSCA_ACCSAL, 'A');
} }
else else
{ {
@ -1102,11 +1119,11 @@ void TPartita::scollega_pagamenti(int r, int s)
for (int j = sc.last(); j > 0; j = sc.pred(j)) for (int j = sc.last(); j > 0; j = sc.pred(j))
{ {
TRectype& pag = sc.row(j); TRectype& pag = sc.row(j);
CHECK(pag.get_real(PAGSCA_ABBUONI).is_zero(), "Can't remove payment with ABBUONI"); CHECK(pag.get_real(PAGSCA_ABBUONI).is_zero(), "Can't detach payment with ABBUONI");
CHECK(pag.get_real(PAGSCA_DIFFCAM).is_zero(), "Can't remove payment with DIFFCAM"); CHECK(pag.get_real(PAGSCA_DIFFCAM).is_zero(), "Can't detach payment with DIFFCAM");
pag.put(PAGSCA_ACCSAL, 'A');
pag.put(PAGSCA_NRIGA, (int)TPartita::UNASSIGNED); pag.put(PAGSCA_NRIGA, (int)TPartita::UNASSIGNED);
pag.put(PAGSCA_NRATA, (int)TPartita::UNASSIGNED); pag.put(PAGSCA_NRATA, (int)TPartita::UNASSIGNED);
pag.put(PAGSCA_ACCSAL, 'A');
if (_unassigned.exist(j)) if (_unassigned.exist(j))
{ {
TRectype& unas = _unassigned.row(j, FALSE); TRectype& unas = _unassigned.row(j, FALSE);

View File

@ -114,12 +114,12 @@ class TRiga_scadenze : public TTree_rectype
TRiga_partite* _riga; TRiga_partite* _riga;
protected: protected:
char calcola_abbuono(int p, TImporto& abbuono) const; char calcola_abbuono(int p, TImporto& abbuono, bool update);
TImporto calcola_differenza_cambio(int p, bool update); TImporto calcola_differenza_cambio(int p, bool update);
bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
char& new_ap, TImporto& new_abb, TImporto& new_diffcam); char& new_ap, TImporto& new_abb, TImporto& new_diffcam, bool update);
bool elimina_pagamento(int p); bool elimina_pagamento(int p);
protected: // TRecord_tree protected: // TRecord_tree
@ -163,6 +163,8 @@ public:
int ultima_ratapagata() const; int ultima_ratapagata() const;
int ultimo_pagamento(int rata) const; int ultimo_pagamento(int rata) const;
int rata_con_abbuoni_diffcam() const;
char sezione() const { return get_char(PART_SEZ); } char sezione() const { return get_char(PART_SEZ); }
bool in_valuta() const { return get(PART_CODVAL).not_empty(); } bool in_valuta() const { return get(PART_CODVAL).not_empty(); }
@ -202,7 +204,7 @@ public:
TRectype& pagamento(int nriga, int nrata, int nrigp); TRectype& pagamento(int nriga, int nrata, int nrigp);
bool rata_chiusa(int nriga, int nrata) const; bool rata_chiusa(int nriga, int nrata) const;
bool esiste(int nriga, int nrata = 0, int nrigp = 0) const; bool esiste(int nriga, int nrata = 0, int nrigp = 0) const;
bool esistono_abbuoni_diffcam() const; bool esistono_abbuoni_diffcam(long nreg = 0) const;
// assegna riga e figli ad altra partita // assegna riga e figli ad altra partita
void sposta_riga(int r, TPartita& part); void sposta_riga(int r, TPartita& part);
@ -222,8 +224,8 @@ public:
int mov2rig(long nreg, int rmov) const; int mov2rig(long nreg, int rmov) const;
int rig2mov(int rmov) const; int rig2mov(int rmov) const;
int prima_fattura(long nreg = -1l) const; int prima_fattura(long nreg = -1) const;
int primo_pagamento(long nreg = -1l) const; int primo_pagamento(long nreg = -1) const;
bool utilizzata(int r) const; // Controlla se esistono pagamenti sommati alla riga r bool utilizzata(int r) const; // Controlla se esistono pagamenti sommati alla riga r
TRecord_array& unassigned() { return _unassigned; } TRecord_array& unassigned() { return _unassigned; }
@ -241,7 +243,8 @@ public:
bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
char& new_ap, TImporto& new_abb, TImporto& new_diffcam); char& new_ap, TImporto& new_abb, TImporto& new_diffcam,
bool update);
bool modifica_pagamento(const TRectype& new_pag); bool modifica_pagamento(const TRectype& new_pag);
TPartita(const TBill& clifo, int anno, const char* num); TPartita(const TBill& clifo, int anno, const char* num);
@ -251,7 +254,7 @@ public:
class TPartite_array : private TAssoc_array class TPartite_array : private TAssoc_array
{ {
TString80 _key; // Work string TString80 _key; // Work string
long _numreg; // Last registration loaded long _numreg; // Last registration loaded
protected: protected:
const TString& key(const TBill& clifo, int anno, const char* num); // Build key for TAssoc_array const TString& key(const TBill& clifo, int anno, const char* num); // Build key for TAssoc_array