campo-sirio/src/cg/cg2106.cpp
Alessandro Bonazzi 3125297772 Patch level : 12.0 1066
Files correlati     : cg2.exe cg4.exe
Commento        :

Le note di credito per cassa non legate a fattura non venivano liquidate dopo un anno.
Corretto errore entrando nel saldaconto

Interno :

Diana
Le note di credito 40177 40178 40179 sono state sganciate per liquidarle ma non venivano liquidate ugualmente dopo un anno.
La registrazione 40178 dava un errore entrando nel saldaconto (cg2)
2021-07-15 23:50:38 +02:00

362 lines
8.9 KiB
C++
Executable File

#include <automask.h>
#include <colors.h>
#include <execp.h>
#include <modaut.h>
#include <treectrl.h>
#include <utility.h>
#include <defmask.h>
#include <varmask.h>
#include "cg2100.h"
#include "cg2102.h"
///////////////////////////////////////////////////////////
// Maschere per colori
///////////////////////////////////////////////////////////
class TColor_mask : public TAutomask
{
const char* const _tipi;
protected:
TProp_field& props() { return (TProp_field&)field(DLG_USER); }
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
void load_props();
void reset_props();
void save_props();
public:
TColor_mask();
};
bool TColor_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case DLG_DELREC:
if (e == fe_button)
{
reset_props();
return false; // Evita chiusura maschera
}
break;
case DLG_USER:
switch (e)
{
case fe_init:
xvt_vobj_maximize(props().win().win());
load_props();
break;
case fe_close:
save_props();
break;
default:
break;
}
break;
default: break;
}
return true;
}
void TColor_mask::load_props()
{
const char* const desc[] =
{
TR("Totale documento/saldo partite"),
TR("Ritenute fiscali"),
TR("Ritenute sociali"),
TR("Generata (Imponibile)"),
TR("IVA detraibile"),
TR("IVA non detraibile"),
TR("Abbuoni attivi"),
TR("Abbuoni passivi"),
TR("Ritenute professionali"),
TR("Differenza cambi"),
TR("Spese"),
TR("Contropartita spese"),
TR("Riga Cliente/Fornitore"),
TR("Riga Collegata")
};
TPrimanota_application& a = app();
TProp_field& ps = props();
ps.freeze(true);
int d = 0;
char prop[4] = "T_B";
for (const char* k = _tipi; *k; k++, d++)
{
COLOR back, fore;
a.type2colors(*k, back, fore);
prop[0] = *k; prop[1] = '\0';
ps.set_property(prop, (const char*)nullptr, desc[d]);
prop[0] = *k; prop[1] = '_'; prop[2] = 'B';
ps.set_property(prop, back, TR("Sfondo"));
prop[2] = 'F';
ps.set_property(prop, fore, TR("Testo"));
}
ps.freeze(false);
}
void TColor_mask::reset_props()
{
TProp_field& ps = props();
ps.freeze(true);
char prop[4] = "T_B";
for (const char* k = _tipi; *k; k++)
{
prop[0] = *k;
prop[2] = 'B';
ps.set_property(prop, NORMAL_BACK_COLOR);
prop[2] = 'F';
ps.set_property(prop, NORMAL_COLOR);
}
ps.freeze(false);
}
void TColor_mask::save_props()
{
TPrimanota_application& a = app();
TProp_field& ps = props();
char prop[4] = "T_B";
for (const char* k = _tipi; *k; k++)
{
prop[0] = *k;
prop[2] = 'B';
const COLOR back = ps.get_color_property(prop);
prop[2] = 'F';
const COLOR fore = ps.get_color_property(prop);
a.set_type_colors(*k, back, fore);
}
}
TColor_mask::TColor_mask() : TAutomask("cg2100k"), _tipi("TFSIDNAPRCGLKX")
{ }
///////////////////////////////////////////////////////////
// Gestione righe colorate
///////////////////////////////////////////////////////////
void TPrimanota_application::load_colors()
{
TConfig conf(CONFIG_USER, "cg2");
TAssoc_array& colori = (TAssoc_array&)conf.list_variables();
for (THash_object* o = colori.get_hashobj(); o; o = colori.get_hashobj())
{
const TString& key = o->key();
if (key.len() == 7 && key.compare("Color", 5, true) == 0)
{
const COLOR col = conf.get_color(key);
TString* strcol = new TString(15);
strcol->format("%ld", col);
_colori.add(key.mid(5), strcol);
}
}
}
void TPrimanota_application::save_colors()
{
TConfig conf(CONFIG_USER, "cg2");
TString16 tmp;
for (THash_object* o = _colori.get_hashobj(); o; o = _colori.get_hashobj())
{
tmp = "Color"; tmp << o->key();
const COLOR col = atol((TString&)o->obj());
bool should_delete = FALSE;
if (tmp[5] == 'B')
should_delete = same_color(col, NORMAL_BACK_COLOR);
else
should_delete = same_color(col, NORMAL_COLOR);
if (should_delete)
conf.remove(tmp);
else
conf.set_color(tmp, col);
}
}
COLOR TPrimanota_application::type2color(char tipor, char tipoc)
{
COLOR col;
if (tipor > ' ')
{
const char key[3] = { tipoc, tipor, '\0' };
TString* colstr = (TString*)_colori.objptr(key);
if (colstr == nullptr)
{
colstr = new TString(8);
if (tipor == 'X')
colstr->format("%ld", tipoc == 'B' ? FOCUS_BACK_COLOR : FOCUS_COLOR);
else
colstr->format("%ld", tipoc == 'B' ? NORMAL_BACK_COLOR : NORMAL_COLOR);
_colori.add(key, colstr);
}
col = atol(*colstr);
}
else
{
col = tipoc == 'B' ? NORMAL_BACK_COLOR : NORMAL_COLOR;
}
return col;
}
void TPrimanota_application::set_type_color(char tipor, char tipoc, COLOR col)
{
if (tipor > ' ')
{
const char key[3] = { tipoc, tipor, '\0' };
TString* colstr = (TString*)_colori.objptr(key);
if (colstr == nullptr)
{
colstr = new TString(8);
_colori.add(key, colstr);
}
colstr->format("%ld", col);
}
}
TMask * TPrimanota_application::mask(CGMaskType type)
{
if (_msk[type] == nullptr)
load_mask(type);
return _msk[type];
}
void TPrimanota_application::type2colors(char tipor, COLOR& back, COLOR& fore)
{
back = type2color(tipor, 'B');
fore = type2color(tipor, 'F');
}
void TPrimanota_application::set_type_colors(char tipor, COLOR back, COLOR fore)
{
set_type_color(tipor, 'B', back);
set_type_color(tipor, 'F', fore);
}
void TPrimanota_application::reset_colors()
{
_colori.destroy();
}
void TPrimanota_application::set_colors()
{
TColor_mask colors;
if (colors.run() == K_ENTER)
save_colors();
else
load_colors();
}
bool TPrimanota_application::colors_handler(TMask_field& f, KEY k)
{
if (k == K_SPACE)
app().set_colors();
return true;
}
#ifdef PRORATA100
///////////////////////////////////////////////////////////
// Gestione cambiamento prorata
///////////////////////////////////////////////////////////
bool TPrimanota_application::test_prorata()
{
if (iva() != iva_acquisti || !cgs().shown() || _as400)
return true;
bool esistono_righe_senza_tipo_detrazione = false;
const TString_array& righe_iva = ivas().rows_array();
for (int r = 0; r < righe_iva.items(); r++)
{
const TToken_string& row = righe_iva.row(r);
real imp_det, iva_det, imp_ind, iva_ind;
get_importi_iva(row, imp_det, iva_det, imp_ind, iva_ind);
if (!iva_det.is_zero())
{
esistono_righe_senza_tipo_detrazione = true;
break;
}
}
bool ok = true;
if (esistono_righe_senza_tipo_detrazione)
{
int annodoc = _msk[2]->get_date(F_DATADOC).year();
if (annodoc < 1900)
annodoc = _msk[2]->get_int(F_ANNOIVA);
const bool prorata100 = causale().reg().prorata100(annodoc);
const bool esiste_riga_iva_detraibile = type2pos('D') >= 0;
if (prorata100)
ok = !esiste_riga_iva_detraibile;
else
ok = _msk[2]->get_real(F_TOTALE).is_zero() || esiste_riga_iva_detraibile;
}
return ok;
}
bool TPrimanota_application::aggiusta_prorata()
{
TWait_cursor hourglass;
if (test_prorata())
return FALSE;
TRegistro& reg = causale().reg();
int annodoc = _msk[2]->get_date(F_DATADOC).year();
if (annodoc < 1900)
annodoc = _msk[2]->get_int(F_ANNOIVA);
const real prorata_attuale = reg.prorata(annodoc);
const real vecchio_prorata = prorata_attuale < CENTO ? CENTO : ZERO;
TSheet_field& iva_sheet = ivas();
TString_array& righe_iva = iva_sheet.rows_array();
TToken_string oldrow(128);
for (int i = 0; i < righe_iva.items(); i++)
{
TToken_string& r = righe_iva.row(i);
if (!r.empty_items())
{
oldrow = r; // Memorizza riga iva
reg.set_prorata(annodoc, vecchio_prorata);
iva_notify(iva_sheet, i, K_SPACE);
r.add("", 0); r.add("", 3); // Simula l'azzeramento degli importi
iva_notify(iva_sheet, i, K_ENTER); // Simula uscita dalla riga
reg.set_prorata(annodoc, prorata_attuale);
iva_notify(iva_sheet, i, K_SPACE);
r = oldrow; // Simula riscrittura importi
iva_notify(iva_sheet, i, K_ENTER); // Simula uscita dalla riga
}
else
break;
}
return true;
}
bool TPrimanota_application::prorata_handler(TMask_field& f, KEY k)
{
if (k == K_SPACE)
{
if (app().aggiusta_prorata())
f.hide();
}
return true;
}
#endif