1197 lines
33 KiB
C++
1197 lines
33 KiB
C++
|
#include <applicat.h>
|
||
|
#include <colors.h>
|
||
|
#include <defmask.h>
|
||
|
#include <progind.h>
|
||
|
#include <tabutil.h>
|
||
|
#include <xvtility.h>
|
||
|
#include <utility.h>
|
||
|
#include <printer.h>
|
||
|
|
||
|
#include "mrplib.h"
|
||
|
#include "../mg/mglib.h"
|
||
|
#include "../ve/velib.h"
|
||
|
#include "../ve/veconf.h"
|
||
|
|
||
|
#include "mr2100.h"
|
||
|
#include "mr2200.h"
|
||
|
|
||
|
#include "mr2200a.h"
|
||
|
#include "mr2200b.h"
|
||
|
|
||
|
// albero per le ricerche sulle dist
|
||
|
static TDistinta_tree *_dist_tree=NULL;
|
||
|
TDistinta_tree &dist_tree()
|
||
|
{
|
||
|
if (!_dist_tree)
|
||
|
_dist_tree=new TDistinta_tree();
|
||
|
return *_dist_tree;
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// triga ordine
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
TMSP_form::TMSP_form (TIsamtempfile * report) :TForm("mr2200a")
|
||
|
{
|
||
|
TRelation* rel = relation();
|
||
|
rel->replace(report);
|
||
|
|
||
|
const int hh = 7;
|
||
|
const int fl = printer().formlen();
|
||
|
|
||
|
int rows[4]; // Righe orizzontali
|
||
|
rows[0] = hh-3;
|
||
|
rows[1] = hh;
|
||
|
rows[2] = fl;
|
||
|
rows[3] = 0;
|
||
|
genera_intestazioni(odd_page, hh-2);
|
||
|
genera_fincatura(odd_page, hh-3, fl, rows);
|
||
|
|
||
|
}
|
||
|
|
||
|
bool TMSP_form::validate(TForm_item &cf, TToken_string &cmd)
|
||
|
{
|
||
|
TString s;
|
||
|
cmd.get(0,s);
|
||
|
if (s=="_USER")
|
||
|
{
|
||
|
TRelation* rel = relation();
|
||
|
cmd.get(1,s);
|
||
|
if (s=="CODART")
|
||
|
{
|
||
|
TString val;
|
||
|
if (rel->lfile().get("TIPO")=="C")
|
||
|
{
|
||
|
val="Ordini in input";
|
||
|
//val << rel->lfile().get("CODART");
|
||
|
//val << " " << rel->lfile(LF_ANAMAG).get("DESCR");
|
||
|
}
|
||
|
else if (rel->lfile().get("TIPO")=="G")
|
||
|
val="Giacenza proiettata";
|
||
|
else
|
||
|
val="Ordini pianificati";
|
||
|
cf.set(val);
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
return TForm::validate(cf,cmd);
|
||
|
}
|
||
|
|
||
|
TCRP_form::TCRP_form(TIsamtempfile * report) :TForm("mr2200b")
|
||
|
{
|
||
|
TRelation* rel = relation();
|
||
|
rel->replace(report);
|
||
|
|
||
|
const int hh = 7;
|
||
|
const int fl = printer().formlen();
|
||
|
|
||
|
int rows[4]; // Righe orizzontali
|
||
|
rows[0] = hh-3;
|
||
|
rows[1] = hh;
|
||
|
rows[2] = fl;
|
||
|
rows[3] = 0;
|
||
|
genera_intestazioni(odd_page, hh-2);
|
||
|
genera_fincatura(odd_page, hh-3, fl, rows);
|
||
|
|
||
|
}
|
||
|
|
||
|
bool TCRP_form::validate(TForm_item &cf, TToken_string &cmd)
|
||
|
{
|
||
|
TString s;
|
||
|
cmd.get(0,s);
|
||
|
if (s=="_USER")
|
||
|
{
|
||
|
TRelation* rel = relation();
|
||
|
cmd.get(1,s);
|
||
|
if (s=="CODART")
|
||
|
{
|
||
|
TString val;
|
||
|
const char type = rel->lfile().get("TIPO")[0];
|
||
|
switch (toupper(type))
|
||
|
{
|
||
|
case 'D':
|
||
|
if (isupper(type))
|
||
|
val << "Totale capacita'";
|
||
|
else
|
||
|
val << " Totale carico ";
|
||
|
break;
|
||
|
case 'I':
|
||
|
if (isupper(type))
|
||
|
val << " Capacita'";
|
||
|
else
|
||
|
val << " Carico";
|
||
|
val << " impianto " << rel->lfile().get("IMPIANTO");
|
||
|
break;
|
||
|
case 'L':
|
||
|
if (isupper(type))
|
||
|
val << " Capacita'";
|
||
|
else
|
||
|
val << " Carico";
|
||
|
val << " linea " << rel->lfile().get("LINEA");
|
||
|
break;
|
||
|
default:
|
||
|
val << " Articolo ";
|
||
|
val << rel->lfile().get("CODART");
|
||
|
val << " " << rel->lfile(LF_ANAMAG).get("DESCR");
|
||
|
break;
|
||
|
}
|
||
|
cf.set(val);
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
return TForm::validate(cf,cmd);
|
||
|
}
|
||
|
|
||
|
|
||
|
int TRiga_articolo::order_comparePCAL(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PCAL);}
|
||
|
int TRiga_articolo::order_comparePCLA(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PCLA);}
|
||
|
int TRiga_articolo::order_comparePALC(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PALC);}
|
||
|
int TRiga_articolo::order_comparePACL(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PACL);}
|
||
|
int TRiga_articolo::order_comparePLAC(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PLAC);}
|
||
|
int TRiga_articolo::order_comparePLCA(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PLCA);}
|
||
|
int TRiga_articolo::order_compareCAL(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_CAL);}
|
||
|
int TRiga_articolo::order_compareCLA(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_CLA);}
|
||
|
int TRiga_articolo::order_compareALC(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_ALC);}
|
||
|
int TRiga_articolo::order_compareACL(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_ACL);}
|
||
|
int TRiga_articolo::order_compareLAC(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_LAC);}
|
||
|
int TRiga_articolo::order_compareLCA(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_LCA);}
|
||
|
int TRiga_articolo::order_comparePCA(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PCA);}
|
||
|
int TRiga_articolo::order_compareCA(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_CA);}
|
||
|
int TRiga_articolo::order_compareAC(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_AC);}
|
||
|
int TRiga_articolo::order_comparePAC(TSheet_field & s, int i1, int i2)
|
||
|
{ return TRiga_articolo::order_compare(s, i1, i2,SORT_BY_PAC);}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// ritorna se tutto OK
|
||
|
bool TRiga_articolo::find_block(const TSheet_field& sf, const int riga, int &first_row, int &last_row )
|
||
|
{
|
||
|
const int narticoli=sf.items();
|
||
|
if (narticoli<=riga)
|
||
|
return FALSE;
|
||
|
// Calcola l'indice c della riga coi vincoli
|
||
|
const int b1 = sf.cid2index(F_BUCKET1);
|
||
|
|
||
|
for (first_row = riga; first_row > 0; first_row--)
|
||
|
{
|
||
|
if (sf.cell_disabled(first_row, b1))
|
||
|
break;
|
||
|
}
|
||
|
if (first_row+1 < narticoli && sf.cell_disabled(first_row+1, b1)) first_row++;
|
||
|
// Calcola l'indice r dell'ultima riga articoli
|
||
|
last_row = riga;
|
||
|
if (last_row <= first_row) last_row=first_row+1;
|
||
|
for ( ; last_row < narticoli-1; last_row++)
|
||
|
{
|
||
|
if (sf.cell_disabled(last_row+1, b1))
|
||
|
break;
|
||
|
}
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
int TRiga_articolo::order_compare( const TToken_string &r1 , const TToken_string &r2 , int level, bool ascending)
|
||
|
{
|
||
|
TString16 str0, str1;
|
||
|
int cmp = 0;
|
||
|
if (level>=0)
|
||
|
{
|
||
|
for (int i = 2; i <= level && cmp == 0; i++)
|
||
|
{
|
||
|
r1.get(i, str0);
|
||
|
r2.get(i, str1);
|
||
|
cmp=TRiga_articolo::compare_field(str0,str1,short(i+FIRST_FIELD));
|
||
|
}
|
||
|
} else {
|
||
|
// ordinamenti non standard
|
||
|
short f;
|
||
|
short fields_ACL[] = {F_ARTICOLO, F_CLIENTE, F_SORTCODIMP, F_SORTCODLIN};
|
||
|
short fields_ALC[] = {F_ARTICOLO, F_SORTCODIMP, F_SORTCODLIN, F_CLIENTE};
|
||
|
short fields_LAC[] = {F_SORTCODIMP, F_SORTCODLIN, F_ARTICOLO, F_CLIENTE};
|
||
|
short fields_LCA[] = {F_SORTCODIMP, F_SORTCODLIN, F_CLIENTE, F_ARTICOLO};
|
||
|
short fields_CLA[] = {F_CLIENTE, F_SORTCODIMP, F_SORTCODLIN, F_ARTICOLO};
|
||
|
short fields_CAL[] = {F_CLIENTE, F_ARTICOLO, F_SORTCODIMP, F_SORTCODLIN};
|
||
|
short fields_CA[] = {F_CLIENTE, F_CLIENTE, F_CLIENTE, F_ARTICOLO};
|
||
|
short fields_AC[] = {F_ARTICOLO, F_CLIENTE, F_CLIENTE, F_CLIENTE};
|
||
|
for (int i = -1; i <= 4 && cmp == 0; i++)
|
||
|
{
|
||
|
if (i<0 || i>3)
|
||
|
{
|
||
|
if (-level <= SORT_BY_PRIORITY == i<0)
|
||
|
f = F_PRIORITA;
|
||
|
else
|
||
|
f = 0;
|
||
|
} else
|
||
|
switch (level)
|
||
|
{
|
||
|
case SORT_BY_PCAL:
|
||
|
case SORT_BY_CAL:
|
||
|
f=fields_CAL[i]; break;
|
||
|
case SORT_BY_PCLA:
|
||
|
case SORT_BY_CLA:
|
||
|
f=fields_CLA[i]; break;
|
||
|
case SORT_BY_PLCA:
|
||
|
case SORT_BY_LCA:
|
||
|
f=fields_LCA[i]; break;
|
||
|
case SORT_BY_PLAC:
|
||
|
case SORT_BY_LAC:
|
||
|
f=fields_LAC[i]; break;
|
||
|
case SORT_BY_PACL:
|
||
|
case SORT_BY_ACL:
|
||
|
f=fields_ACL[i]; break;
|
||
|
case SORT_BY_PALC:
|
||
|
case SORT_BY_ALC:
|
||
|
f=fields_ALC[i]; break;
|
||
|
case SORT_BY_PAC:
|
||
|
case SORT_BY_AC:
|
||
|
f=fields_AC[i]; break;
|
||
|
case SORT_BY_PCA:
|
||
|
case SORT_BY_CA:
|
||
|
f=fields_CA[i]; break;
|
||
|
default:
|
||
|
NFCHECK("Ordinamento sconosciuto");
|
||
|
break;
|
||
|
}
|
||
|
if (f)
|
||
|
{
|
||
|
r1.get(f-FIRST_FIELD, str0);
|
||
|
r2.get(f-FIRST_FIELD, str1);
|
||
|
cmp=TRiga_articolo::compare_field(str0,str1,f) * (ascending && f != F_PRIORITA ? 1 : -1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return cmp;
|
||
|
}
|
||
|
|
||
|
|
||
|
// aggiunge li codici di linea/impianto se non presenti usando i default sulle lavorazioni critiche
|
||
|
// cio' permette di ordinare per impianto anche le linee di ordine che non hanno solitamente
|
||
|
// questa indicazione ma solo il codice articolo
|
||
|
void complete_codlinea(TToken_string &r2, bool ignore_imp)
|
||
|
{
|
||
|
TString8 swp;
|
||
|
r2.get(F_SORTCODLIN-FIRST_FIELD,swp);
|
||
|
if (swp.blank())
|
||
|
{
|
||
|
r2.get(F_CODLIN-FIRST_FIELD,swp);
|
||
|
if (swp.blank())
|
||
|
{
|
||
|
if (dist_tree().set_root(r2.get(F_ARTICOLO-FIRST_FIELD)))
|
||
|
{
|
||
|
TString codimp(r2.get(F_CODIMP-FIRST_FIELD));
|
||
|
dist_tree().set_global("_IMPIANTO",codimp);
|
||
|
dist_tree().set_global("_LINEA","");
|
||
|
//dist_tree().set_global("_LIVELLO",);
|
||
|
//dist_tree().set_global("_MAGAZZINO",);
|
||
|
TArray labors;
|
||
|
TRiga_esplosione * l=dist_tree().first_critical_labor(labors);
|
||
|
if (l)
|
||
|
{
|
||
|
TLavorazione *curr_labor=TDistinta_tree::find_labor(l);
|
||
|
CHECK(curr_labor,"Lavorazione non trovata");
|
||
|
for (int nlinea=0; nlinea <curr_labor->linee_standard(); nlinea ++)
|
||
|
{
|
||
|
const TRectype &linea_prod= cache().get("LNP",curr_labor->cod_linea(nlinea));
|
||
|
if ( ignore_imp || codimp.blank() || codimp==linea_prod.get("S6"))
|
||
|
{
|
||
|
r2.add(linea_prod.get("CODTAB"), F_SORTCODLIN-FIRST_FIELD);
|
||
|
r2.add(linea_prod.get("S6"), F_SORTCODIMP-FIRST_FIELD);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
r2.add('\255', F_SORTCODLIN-FIRST_FIELD);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
r2.add(swp, F_SORTCODLIN-FIRST_FIELD);
|
||
|
r2.get(F_CODLIN-FIRST_FIELD,swp);
|
||
|
r2.add(swp, F_SORTCODIMP-FIRST_FIELD);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int TRiga_articolo::order_compare(TSheet_field & s, int i1, int i2, int level)
|
||
|
{
|
||
|
TMask &m=s.mask();
|
||
|
const bool ascending=!m.get_bool(F_MSP_SORT_ORDER);
|
||
|
int first1, first2, last1, last2;
|
||
|
|
||
|
if (find_block(s, i1, first1, last1 )) first1--;
|
||
|
if (find_block(s, i2, first2, last2 )) first2--;
|
||
|
|
||
|
const TToken_string &r1 = s.row(i1);
|
||
|
const TToken_string &r2 = s.row(i2);
|
||
|
if (s.cell_enabled(i1, F_BUCKET1-FIRST_FIELD) && s.cell_enabled(i2, F_BUCKET1-FIRST_FIELD) )
|
||
|
{
|
||
|
// confronto tra righe dello stesso vincolo
|
||
|
if (first1 == first2 )
|
||
|
return order_compare( r1 , r2 , level, ascending);
|
||
|
} else {
|
||
|
if (first1 != first2 && first1==i1 && first2==i2 )
|
||
|
{
|
||
|
TToken_string &blockr1=(TToken_string &)r1;
|
||
|
TToken_string &blockr2=(TToken_string &)r2;;
|
||
|
if (!(-level & SORT_WITHOUT_LINE))
|
||
|
{
|
||
|
complete_codlinea(blockr1, m.get_bool(F_NOIMP_IN));
|
||
|
complete_codlinea(blockr2, m.get_bool(F_NOIMP_IN));
|
||
|
}
|
||
|
// confronto tra blocchi ed eventuale swap direttamente qui nella compare
|
||
|
int cmp = order_compare(blockr1 , blockr2 , level, ascending );
|
||
|
if (cmp > 0)
|
||
|
{
|
||
|
for (int bubble=first2; bubble<=last2; bubble++)
|
||
|
{
|
||
|
for (int r=bubble; r>bubble+first1-first2; r--)
|
||
|
{
|
||
|
s.swap_rows(r, r-1);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
int TRiga_articolo::compare_field(TString &str0, TString &str1,short field_no)
|
||
|
{
|
||
|
int cmp;
|
||
|
switch (field_no)
|
||
|
{
|
||
|
case F_CLIENTE:
|
||
|
{
|
||
|
const long f0 = atol(str0);
|
||
|
const long f1 = atol(str1);
|
||
|
cmp = f0 == f1 ? 0 : (f0 > f1 ? +1 : -1);
|
||
|
}
|
||
|
break;
|
||
|
case F_PRIORITA:
|
||
|
cmp = atoi(str0) - atoi(str1);
|
||
|
break;
|
||
|
default:
|
||
|
cmp = str0.compare(str1);
|
||
|
break;
|
||
|
}
|
||
|
return cmp;
|
||
|
}
|
||
|
|
||
|
TRiga_articolo& TRiga_articolo::operator=(TToken_string& r)
|
||
|
{
|
||
|
this->TToken_string::operator=(r);
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
TRiga_articolo& TRiga_articolo::operator+=(TRiga_articolo& r)
|
||
|
{
|
||
|
NFCHECK( "Can't add incompatible order line");
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
TRiga_articolo::TRiga_articolo(const TMSP_constraint& line)
|
||
|
: TToken_string(128)
|
||
|
{
|
||
|
format("%ld", line.cliente());
|
||
|
add(line.codice(),F_CLIENTE-FIRST_FIELD);
|
||
|
add(" ",F_PRIORITA-FIRST_FIELD);
|
||
|
|
||
|
const TString& liv = line.livgiac();
|
||
|
for (int l = 1; l <= 4; l++)
|
||
|
{
|
||
|
if (livelli_giac().enabled(l))
|
||
|
add(livelli_giac().unpack_grpcode(liv,l),F_LIV1+l-1-FIRST_FIELD);
|
||
|
else
|
||
|
add(" ",F_LIV1+l-1-FIRST_FIELD);
|
||
|
}
|
||
|
|
||
|
add(line.desc(),F_DESCART-FIRST_FIELD);
|
||
|
add(line.codimp(),F_CODIMP-FIRST_FIELD);
|
||
|
add(line.codlin(),F_CODLIN-FIRST_FIELD);
|
||
|
|
||
|
TString8 str = line.codmag().left(3);
|
||
|
add(str, F_MAGAZZINO-FIRST_FIELD);
|
||
|
str = line.codmag().mid(3);
|
||
|
add(str, F_DEPOSITO-FIRST_FIELD);
|
||
|
|
||
|
const TCodice_um um;
|
||
|
const TQuantita qta_art(line.codice(), um, ZERO);
|
||
|
add(qta_art.um(),F_UM-FIRST_FIELD);
|
||
|
|
||
|
TMSP_constraint& lin=(TMSP_constraint& )line;
|
||
|
const int last_buck= line.last();
|
||
|
for (int bu = 0; bu <= last_buck; bu ++)
|
||
|
{
|
||
|
add(lin.qta(bu).string(), bu*2+F_BUCKET0-FIRST_FIELD);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
TObject* TMSP_record::dup() const
|
||
|
{
|
||
|
TMSP_record* o=new TMSP_record();
|
||
|
o->_numdoc=_numdoc;
|
||
|
o->_numrig=_numrig;
|
||
|
o->_qta=_qta;
|
||
|
o->_price=_price;
|
||
|
return o;
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
TMSP_record& TMSP_record_array::operator[](int b)
|
||
|
{
|
||
|
CHECKD(b >= 0, "Invalid TMSP_record_array ", b);
|
||
|
TMSP_record* rec = (TMSP_record*)_buckets.objptr(b);
|
||
|
if (rec == NULL)
|
||
|
{
|
||
|
rec = new TMSP_record;
|
||
|
_buckets.add(rec, b);
|
||
|
}
|
||
|
return *rec;
|
||
|
}
|
||
|
|
||
|
TMSP_record_array& TMSP_record_array::operator=(const TMSP_record_array& a)
|
||
|
{
|
||
|
_buckets = a._buckets;
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
TCapacita_prod::TCapacita_prod () :
|
||
|
_capacity(), _load()
|
||
|
{ }
|
||
|
|
||
|
TCapacita_prod::TCapacita_prod (const real& cap, const real& load) :
|
||
|
_capacity(cap), _load(load)
|
||
|
{ }
|
||
|
|
||
|
void TCapacita_prod::set(const real& cap, const real& load)
|
||
|
{ _capacity=(cap);_load=(load);}
|
||
|
|
||
|
void TCapacita_prod::copy (const TCapacita_prod & q)
|
||
|
{
|
||
|
_capacity=q._capacity; // Valore attuale
|
||
|
_load=q._load; // Valore attuale
|
||
|
}
|
||
|
|
||
|
int TCapacita_prod::compare(const TSortable& s) const
|
||
|
{
|
||
|
TCapacita_prod& c=(TCapacita_prod&)s;
|
||
|
real r=_capacity-c._capacity;
|
||
|
return r.sign();
|
||
|
}
|
||
|
|
||
|
|
||
|
TCRP_line::TCRP_line(const TString& codimp,const TString& codlin)
|
||
|
: _lineap(codlin),_on_sheet(FALSE)
|
||
|
{
|
||
|
if (!codlin.blank())
|
||
|
{
|
||
|
TTable tablnp("LNP");
|
||
|
tablnp.put("CODTAB",_lineap);
|
||
|
tablnp.read();
|
||
|
_desc = tablnp.get("S0");
|
||
|
_imp = tablnp.get("S6");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_imp = codimp ;
|
||
|
if (!codimp.blank())
|
||
|
{
|
||
|
TTable tabimp("IMP");
|
||
|
tabimp.put("CODTAB",_imp);
|
||
|
tabimp.read();
|
||
|
_desc = tabimp.get("S0");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_desc = "Totale ditta";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int TCRP_line::compare(const TSortable& s) const
|
||
|
{
|
||
|
const TCRP_line& c = (const TCRP_line&)s;
|
||
|
int cmp = _imp.compare(c._imp);
|
||
|
if (cmp == 0)
|
||
|
{
|
||
|
cmp = _lineap.compare(c._lineap);
|
||
|
}
|
||
|
return cmp;
|
||
|
}
|
||
|
|
||
|
// carica una riga di sheet con i dati dell'oggetto vincolo
|
||
|
void TCRP_line::fill_capacity_row(TToken_string& row, bool percent)
|
||
|
{
|
||
|
row.add(codimp(),F_CODIMPCRP -FIRST_FIELD);
|
||
|
row.add(codlin(),F_CODLINCRP -FIRST_FIELD);
|
||
|
|
||
|
row.add(percent ? "%": "ore",F_LUM -FIRST_FIELD);
|
||
|
|
||
|
real r;
|
||
|
for (int bu = last(); bu > 0; bu = pred(bu))
|
||
|
{
|
||
|
r=capacity(bu);
|
||
|
if (!r.is_zero())
|
||
|
row.add(percent ? "100" : r.string(), bu + F_LBUCKET0 -FIRST_FIELD); // buckets
|
||
|
else
|
||
|
row.add("", bu + F_LBUCKET0 -FIRST_FIELD);
|
||
|
}
|
||
|
}
|
||
|
void TCRP_line::fill_hcapacity_row(TToken_string& row, bool percent)
|
||
|
{
|
||
|
row.add(codimp(),F_CODIMPCRP -FIRST_FIELD);
|
||
|
row.add(codlin(),F_CODLINCRP -FIRST_FIELD);
|
||
|
|
||
|
row.add(percent ? "%": "ore",F_LUM -FIRST_FIELD);
|
||
|
|
||
|
real r;
|
||
|
for (int bu = last(); bu > 0; bu = pred(bu))
|
||
|
{
|
||
|
r=human_capacity(bu);
|
||
|
if (!r.is_zero())
|
||
|
row.add(percent ? "100" : r.string(), bu + F_LBUCKET0 -FIRST_FIELD); // buckets
|
||
|
else
|
||
|
row.add("", bu + F_LBUCKET0 -FIRST_FIELD);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// carica una riga di sheet con i dati dell'oggetto vincolo
|
||
|
void TCRP_line::fill_load_row(TToken_string& row, bool percent)
|
||
|
{
|
||
|
row.add(codimp(),F_CODIMPCRP -FIRST_FIELD);
|
||
|
row.add(codlin(),F_CODLINCRP -FIRST_FIELD);
|
||
|
|
||
|
row.add(percent ? "%": "ore",F_LUM -FIRST_FIELD);
|
||
|
|
||
|
real r;
|
||
|
for (int bu = last(); bu > 0; bu = pred(bu))
|
||
|
{
|
||
|
r=percent ? (capacity(bu).is_zero() ? ZERO : (100L * load(bu) / capacity(bu))) : load(bu) ;
|
||
|
row.add(r.string(), bu + F_LBUCKET0 -FIRST_FIELD); // buckets
|
||
|
}
|
||
|
}
|
||
|
void TCRP_line::fill_hload_row(TToken_string& row, bool percent)
|
||
|
{
|
||
|
row.add(codimp(),F_CODIMPCRP -FIRST_FIELD);
|
||
|
row.add(codlin(),F_CODLINCRP -FIRST_FIELD);
|
||
|
|
||
|
row.add(percent ? "%": "ore",F_LUM -FIRST_FIELD);
|
||
|
|
||
|
real r;
|
||
|
for (int bu = last(); bu > 0; bu = pred(bu))
|
||
|
{
|
||
|
r=percent ? (human_capacity(bu).is_zero() ? ZERO :(100L * human_load(bu) / human_capacity(bu))) : human_load(bu) ;
|
||
|
row.add(r.string(), bu + F_LBUCKET0 -FIRST_FIELD); // buckets
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
TCapacita_prod& TCRP_line::bucket(int n)
|
||
|
{
|
||
|
TCapacita_prod *o;
|
||
|
o=(TCapacita_prod *)_bucket.objptr(n);
|
||
|
if (o==NULL)
|
||
|
{
|
||
|
o=new TCapacita_prod();
|
||
|
_bucket.add(o,n);
|
||
|
}
|
||
|
return *o;
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TCRP_lines ; carichi delle varie linee
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
TSortable* TCRP_lines::new_obj(const TToken_string& key) const
|
||
|
{
|
||
|
TString8 codimp, codlin;
|
||
|
key.get(0,codimp);
|
||
|
key.get(1,codlin);
|
||
|
return new TCRP_line(codimp, codlin);
|
||
|
}
|
||
|
|
||
|
TCRP_line* TCRP_lines::find(const TLinea_prod& linea_prod, const char * codart, long codcli, bool create)
|
||
|
{
|
||
|
/* _key=linea_prod.codimp();
|
||
|
_key.add(linea_prod.codice());
|
||
|
TSortable* s = create ? add_obj(_key) : find_obj(_key);
|
||
|
return (TCRP_line*)s;*/
|
||
|
TString8 codimp(linea_prod.codimp());
|
||
|
TString8 codlin(linea_prod.codice());
|
||
|
return find(codimp, codlin ,codart, codcli, create);
|
||
|
}
|
||
|
|
||
|
TCRP_line* TCRP_lines::find(const char * codimp, const char * codlin, const char * codart, long codcli, bool create)
|
||
|
{
|
||
|
_key.add(codimp,0);
|
||
|
_key.add(codlin,1);
|
||
|
_key.add(codart,2); // articolo
|
||
|
_key.add(format("%ld",codcli),3); // cliente
|
||
|
TSortable* s = create ? add_obj(_key) : find_obj(_key);
|
||
|
return (TCRP_line*)s;
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TMaster_code
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
TMaster_code::TMaster_code(const char *code, const char *liv,const char *ummaster, const real &expr, const real &leadtime, const char *codimp, const char *codlin, const char *codmag)
|
||
|
: _code(code), _liv (liv), _um(ummaster), _expr(expr), _leadtime(leadtime),
|
||
|
_codimp(codimp), _codlin(codlin), _codmag(codmag)
|
||
|
{
|
||
|
}
|
||
|
TMaster_code::TMaster_code(const char *code, const char *liv,const char *ummaster, const real &expr, int leadtime, const char *codimp, const char *codlin, const char *codmag)
|
||
|
: _code(code), _liv (liv), _um(ummaster), _expr(expr), _leadtime(format("%d",leadtime)),
|
||
|
_codimp(codimp), _codlin(codlin), _codmag(codmag)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TMSP_line2
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
void TMSP_line2::add_mastercode (TMaster_code *mc)
|
||
|
{
|
||
|
_mastercodes.add(mc);
|
||
|
}
|
||
|
|
||
|
TMaster_code *TMSP_line2::get_mastercode (int i)
|
||
|
{
|
||
|
if (i>=0 && i < _mastercodes.items())
|
||
|
return (TMaster_code *) _mastercodes.objptr(i);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
TMSP_line2::TMSP_line2(const TMSP_constraint &c)
|
||
|
{
|
||
|
_constraint = new TMSP_constraint(c);
|
||
|
*_constraint = c;
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TMSP_constraint
|
||
|
///////////////////////////////////////////////////////////
|
||
|
int TMSP_constraint::compare(const TSortable& s) const
|
||
|
{
|
||
|
const TMSP_constraint& c = (const TMSP_constraint&)s;
|
||
|
const long diff = _cliente - c._cliente;
|
||
|
int cmp = diff == 0L ? 0 : (diff > 0 ? +1 : -1);
|
||
|
if (cmp == 0)
|
||
|
{
|
||
|
cmp = _codart.compare(c._codart);
|
||
|
if (cmp == 0)
|
||
|
{
|
||
|
cmp = _giac.compare(c._giac);
|
||
|
if (cmp == 0)
|
||
|
{
|
||
|
cmp = _imp.compare(c._imp);
|
||
|
if (cmp == 0)
|
||
|
cmp = _mag.compare(c._mag);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return cmp;
|
||
|
}
|
||
|
|
||
|
|
||
|
// carica una riga di sheet con i dati dell'oggetto vincolo
|
||
|
void TMSP_constraint::fill_sheet_row(TToken_string& row, const TMask & m, bool codes_only)
|
||
|
{
|
||
|
TString tipocf(m.get(F_TIPOCF));
|
||
|
|
||
|
row.add(m.get_bool(F_NOCLI_IN) ? "" : tipocf,F_TIPOCF_SHEET-FIRST_FIELD);
|
||
|
|
||
|
row.add(format("%ld", cliente()),F_CLIENTE-FIRST_FIELD);
|
||
|
row.add(codice(),F_ARTICOLO-FIRST_FIELD);
|
||
|
row.add(" ",F_PRIORITA-FIRST_FIELD);
|
||
|
|
||
|
const TString& liv = livgiac();
|
||
|
for (int l = 1; l <= 4; l++)
|
||
|
{
|
||
|
if (livelli_giac().enabled(l))
|
||
|
row.add(livelli_giac().unpack_grpcode(liv,l),F_LIV1+l-1-FIRST_FIELD);
|
||
|
else
|
||
|
row.add(" ",F_LIV1+l-1-FIRST_FIELD);
|
||
|
}
|
||
|
|
||
|
row.add(desc(),F_DESCART-FIRST_FIELD);
|
||
|
row.add(codimp(),F_CODIMP-FIRST_FIELD);
|
||
|
row.add(codlin(),F_CODLIN-FIRST_FIELD);
|
||
|
|
||
|
TString8 str = _mag.left(3);
|
||
|
row.add(str, F_MAGAZZINO-FIRST_FIELD);
|
||
|
str = _mag.mid(3);
|
||
|
row.add(str,F_DEPOSITO-FIRST_FIELD);
|
||
|
|
||
|
const TCodice_um um;
|
||
|
const TQuantita qta_art(codice(), um, ZERO);
|
||
|
row.add(qta_art.um(),F_UM-FIRST_FIELD);
|
||
|
|
||
|
if (codes_only)
|
||
|
return;
|
||
|
real needs=ZERO;
|
||
|
const int last_buck= last();
|
||
|
for (int bu = 0; bu <= last_buck; bu ++)
|
||
|
{
|
||
|
needs=qta(bu);
|
||
|
row.add(needs.string(), bu*2+F_BUCKET0-FIRST_FIELD);
|
||
|
needs=price(bu);
|
||
|
row.add(needs.string(), bu*2+F_BUCKET0+1-FIRST_FIELD);
|
||
|
}
|
||
|
row.add(mastercodes2check() ? MASTERCODE_CHAR : ' ',F_MASTERCODE-FIRST_FIELD);
|
||
|
}
|
||
|
|
||
|
bool TMSP_constraint::riga(int buck, long& ndoc, int& nrig)
|
||
|
{
|
||
|
TMSP_record& b = _bucket_qta[buck];
|
||
|
ndoc = b._numdoc;
|
||
|
nrig = b._numrig;
|
||
|
return ndoc > 0L && nrig > 0;
|
||
|
}
|
||
|
|
||
|
void TMSP_constraint::set_riga(int buck, char provv, TString& codnum, int annodoc, long ndoc, int nrig)
|
||
|
{
|
||
|
TMSP_record& b = _bucket_qta[buck];
|
||
|
b._numdoc = ndoc;
|
||
|
b._numrig = nrig;
|
||
|
}
|
||
|
|
||
|
int TMSP_constraint::find_distinta_master(const TMSP_constraint & constr, TString & master,TString & livmaster,TString & um, real & expr, TString & imp,TString & lin,TString & magdep, int fromindex)
|
||
|
{
|
||
|
TArray sons;
|
||
|
if (dist_tree().set_root(constr.codice()))
|
||
|
{
|
||
|
dist_tree().set_global("_LIVELLO",constr.livgiac());
|
||
|
dist_tree().set_global("_IMPIANTO",constr.codimp());
|
||
|
dist_tree().set_global("_LINEA",constr.codlin());
|
||
|
dist_tree().set_global("_MAGAZZINO",constr.codmag());
|
||
|
dist_tree().explode(sons, FALSE, RAGGR_EXP_NONE, 1);
|
||
|
TRiga_esplosione* riga;
|
||
|
while (riga=(TRiga_esplosione* )sons.objptr(fromindex))
|
||
|
{
|
||
|
if (distinta_master(riga->articolo()))
|
||
|
{
|
||
|
master=riga->articolo();
|
||
|
livmaster=riga->livello();
|
||
|
um =riga->um();
|
||
|
expr =riga->val();
|
||
|
return fromindex;
|
||
|
}
|
||
|
fromindex=sons.succ(fromindex);
|
||
|
}
|
||
|
}
|
||
|
master="";
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool TMSP_constraint::mastercodes2check() const
|
||
|
{
|
||
|
return _check_master;
|
||
|
}
|
||
|
|
||
|
void TMSP_constraint::set_mastercode_check(bool on)
|
||
|
{
|
||
|
_check_master=on;
|
||
|
}
|
||
|
|
||
|
TMSP_line2 *TMSP_constraint::use_mspline2(TToken_string & row, TSheet_field & sf)
|
||
|
{
|
||
|
TString16 liv;
|
||
|
TString8 mag,imp,lin;
|
||
|
long codcli=row.get_long(F_CLIENTE-FIRST_FIELD);
|
||
|
livelli_giac().pack_grpcode(liv, row.get(sf.cid2index(F_LIV1)),1);
|
||
|
livelli_giac().pack_grpcode(liv, row.get(sf.cid2index(F_LIV2)),2);
|
||
|
livelli_giac().pack_grpcode(liv, row.get(sf.cid2index(F_LIV3)),3);
|
||
|
livelli_giac().pack_grpcode(liv, row.get(sf.cid2index(F_LIV4)),4);
|
||
|
imp=row.get(sf.cid2index(F_CODIMP));
|
||
|
lin=row.get(sf.cid2index(F_CODLIN));
|
||
|
add_magcode(mag, row.get(sf.cid2index(F_MAGAZZINO)));
|
||
|
add_depcode(mag, row.get(sf.cid2index(F_DEPOSITO)));
|
||
|
codcli=row.get_long(F_CLIENTE-FIRST_FIELD);
|
||
|
TMSP_line mspline(codcli, codice(), liv, imp, lin, mag);
|
||
|
for (int b= 1 ; b< LAST_BUCKET ; b++)
|
||
|
{
|
||
|
real q(row.get(sf.cid2index(F_BUCKET0+b*2)));
|
||
|
mspline.qta(b) = q;
|
||
|
}
|
||
|
return use_mspline2(mspline);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
TMSP_line2 *TMSP_constraint::use_mspline2(TMSP_constraint &line)
|
||
|
{
|
||
|
TMSP_line2 *a=NULL;
|
||
|
for (int i=_lines2.items()-1; i>=0 && a==NULL; i--)
|
||
|
{
|
||
|
a=(TMSP_line2 *) _lines2.objptr(i);
|
||
|
if (a->constraint() != line)
|
||
|
a=NULL;
|
||
|
}
|
||
|
if (a == NULL)
|
||
|
{
|
||
|
TString master;
|
||
|
TString4 ummaster;
|
||
|
TString16 livmaster;
|
||
|
TString8 impmaster(codimp()), linmaster(codlin()),magmaster(codmag());
|
||
|
real expr;
|
||
|
int dm=0;
|
||
|
while ((dm=find_distinta_master(line, master, livmaster, ummaster, expr, impmaster, linmaster, magmaster,dm)+1) >0)
|
||
|
{
|
||
|
if (a == NULL)
|
||
|
{
|
||
|
a = new TMSP_line2(line);
|
||
|
_lines2.add(a);
|
||
|
}
|
||
|
a->add_mastercode(new TMaster_code (master, livmaster, ummaster, expr, cache().get(LF_ANAMAG,master).get_real(ANAMAG_GIORNIRIOR), codimp(), codlin(), codmag()));
|
||
|
}
|
||
|
}
|
||
|
if (a)
|
||
|
{
|
||
|
a->set_use(TRUE);
|
||
|
a->constraint() = line;
|
||
|
}
|
||
|
return a;
|
||
|
}
|
||
|
|
||
|
void TMSP_constraint::reset_unused_line2()
|
||
|
{
|
||
|
TMSP_line2 *a;
|
||
|
for (int i=_lines2.items()-1; i>=0; i--)
|
||
|
{
|
||
|
a=(TMSP_line2 *) _lines2.objptr(i);
|
||
|
a->set_use(FALSE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
TMSP_line2 * TMSP_constraint::get_unused_line2()
|
||
|
{
|
||
|
TMSP_line2 *a;
|
||
|
for (int i=_lines2.items()-1; i>=0; i--)
|
||
|
{
|
||
|
a=(TMSP_line2 *) _lines2.objptr(i);
|
||
|
if (!a->used())
|
||
|
return a;
|
||
|
}
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
void TMSP_constraint::discard_line2(TMSP_line2 * l)
|
||
|
{
|
||
|
TMSP_line2 *a;
|
||
|
int i=_lines2.items();
|
||
|
while (--i>=0)
|
||
|
{
|
||
|
a=(TMSP_line2 *) _lines2.objptr(i);
|
||
|
if (a==l)
|
||
|
{
|
||
|
_lines2.destroy(i,TRUE);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool TMSP_constraint::has_upperlines() const
|
||
|
{
|
||
|
return _upperlines.items()>0;
|
||
|
}
|
||
|
|
||
|
TMSP_constraint * TMSP_constraint::add_upperline(const TMSP_constraint& mc)
|
||
|
{
|
||
|
if (_upperlines.items()==0)
|
||
|
{
|
||
|
// aggiunge se stesso
|
||
|
TMSP_constraint * myself=_upperlines.find(cliente(), codice(), livgiac(),
|
||
|
codimp(),codlin(),codmag(),TRUE);
|
||
|
*myself=*this;
|
||
|
}
|
||
|
return _upperlines.find(mc.cliente(), mc.codice(), mc.livgiac(),
|
||
|
mc.codimp(),mc.codlin(),mc.codmag(),TRUE);
|
||
|
}
|
||
|
|
||
|
TMSP_constraint* TMSP_constraint::get_upperline(TMSP_constraint& mc)
|
||
|
{
|
||
|
return _upperlines.find(mc.cliente(), mc.codice(), mc.livgiac(),
|
||
|
mc.codimp(),mc.codlin(),mc.codmag(),FALSE);
|
||
|
}
|
||
|
|
||
|
TMSP_constraint & TMSP_constraint::operator=(const TMSP_constraint & line)
|
||
|
{
|
||
|
_cliente=line.cliente();
|
||
|
_codart=line.codice();
|
||
|
_giac=line.livgiac();
|
||
|
_imp=line.codimp();
|
||
|
_lin=line.codlin();
|
||
|
_mag=line.codmag();
|
||
|
_on_sheet=_on_sheet;
|
||
|
_desc=line.desc();
|
||
|
_bucket_qta=line._bucket_qta;
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
|
||
|
TMSP_constraint::TMSP_constraint(long cliente,
|
||
|
const TCodice_articolo& codart,
|
||
|
const TString& giac,
|
||
|
const TString& imp,
|
||
|
const TString& lin,
|
||
|
const TString& mag)
|
||
|
: _cliente(cliente), _codart(codart), _giac(giac),
|
||
|
_imp(imp), _lin(lin), _mag(mag),_on_sheet(FALSE),_check_master(FALSE)
|
||
|
{ }
|
||
|
|
||
|
TMSP_constraint::TMSP_constraint(const TMSP_constraint & line)
|
||
|
: _cliente(line.cliente()), _codart(line.codice()), _giac(line.livgiac()),
|
||
|
_imp(line.codimp()), _lin(line.codlin()), _mag(line.codmag()), _on_sheet(FALSE),
|
||
|
_check_master(FALSE), _desc(line.desc())
|
||
|
{
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TMSP_constraints
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
TSortable* TMSP_constraints::new_obj(const TToken_string& key) const
|
||
|
{
|
||
|
long cli; key.get(0, cli);
|
||
|
TCodice_articolo art; key.get(1, art); art.trim();
|
||
|
TString16 gia; key.get(2, gia); gia.trim();
|
||
|
TString8 imp; key.get(3, imp); imp.trim();
|
||
|
TString8 lin; key.get(4, lin); lin.trim();
|
||
|
TString8 mag; key.get(5, mag); mag.trim();
|
||
|
return new TMSP_constraint(cli, art, gia, imp, lin, mag);
|
||
|
}
|
||
|
|
||
|
TMSP_constraint* TMSP_constraints::find(long cliente,
|
||
|
const TString& art,
|
||
|
const TString& gia,
|
||
|
const TString& imp,
|
||
|
const TString& lin,
|
||
|
const TString& mag,
|
||
|
bool create)
|
||
|
{
|
||
|
_key.format("%ld", cliente);
|
||
|
_key.add(art);_key.trim();
|
||
|
_key.add(gia);_key.trim();
|
||
|
_key.add(imp);_key.trim();
|
||
|
_key.add(lin);_key.trim();
|
||
|
_key.add(mag);_key.trim();
|
||
|
TSortable* s = create ? add_obj(_key) : find_obj(_key);
|
||
|
TMSP_constraint *c=(TMSP_constraint*)s;
|
||
|
if (create)
|
||
|
{
|
||
|
if (c->desc().blank())
|
||
|
c->set_desc(cache().get(LF_ANAMAG,art).get("DESCR"));
|
||
|
}
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
//////////////////////////////////////////////////////////
|
||
|
// TMSP_line
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
void TMSP_line::fill_sheet_row(TToken_string& row, const TMask & m, bool codes_only)
|
||
|
{
|
||
|
TMSP_constraint::fill_sheet_row(row, m, codes_only);
|
||
|
row.add(m.get(F_TIPOCF),F_TIPOCF_SHEET-FIRST_FIELD);
|
||
|
}
|
||
|
|
||
|
TMSP_line::TMSP_line(long cliente, const TCodice_articolo& codart,
|
||
|
const TString& giac, const TString& imp,
|
||
|
const TString& lin, const TString& mag)
|
||
|
: TMSP_constraint(cliente, codart, giac, imp, lin,mag)
|
||
|
{ }
|
||
|
|
||
|
TMSP_line::TMSP_line(TMSP_constraint & cons)
|
||
|
:TMSP_constraint(cons)
|
||
|
{ }
|
||
|
TMSP_line::TMSP_line(TMSP_line & line)
|
||
|
:TMSP_constraint((TMSP_constraint &)line)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TMSP_lines
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
TSortable* TMSP_lines::new_obj(const TToken_string& key) const
|
||
|
{
|
||
|
long cliente; key.get(0, cliente);
|
||
|
TCodice_articolo art; key.get(1, art); art.trim();
|
||
|
TString gia; key.get(2, gia); gia.trim();
|
||
|
TString imp; key.get(3, imp); imp.trim();
|
||
|
TString lin; key.get(4, lin); lin.trim();
|
||
|
TString mag; key.get(5, mag); mag.trim();
|
||
|
return new TMSP_line(cliente, art, gia, imp, lin, mag);
|
||
|
}
|
||
|
|
||
|
TMSP_line* TMSP_lines::find(long cliente,
|
||
|
const TString& art,
|
||
|
const TString& gia, const TString& imp,
|
||
|
const TString& lin, const TString& mag,
|
||
|
bool create)
|
||
|
{
|
||
|
_key.format("%ld", cliente);
|
||
|
_key.add(art);
|
||
|
_key.add(gia);
|
||
|
_key.add(imp);
|
||
|
_key.add(lin);
|
||
|
_key.add(mag);
|
||
|
TSortable* s = create ? add_obj(_key) : find_obj(_key);
|
||
|
return (TMSP_line*)s;
|
||
|
}
|
||
|
|
||
|
TMSP_line* TMSP_lines::find(const TToken_string& row, bool create)
|
||
|
{
|
||
|
TString80 str,giaclev;
|
||
|
_key.cut(0);
|
||
|
|
||
|
for (int i = 0; i <= 11; i++)
|
||
|
{
|
||
|
row.get(i, str);
|
||
|
str.trim();
|
||
|
switch (i+FIRST_FIELD)
|
||
|
{
|
||
|
case F_LIV1:
|
||
|
case F_LIV2:
|
||
|
case F_LIV3:
|
||
|
livelli_giac().pack_grpcode(giaclev, str, i+FIRST_FIELD-F_LIV1+1); break;
|
||
|
case F_LIV4:
|
||
|
livelli_giac().pack_grpcode(giaclev, str, 4);
|
||
|
giaclev.trim();
|
||
|
_key.add(giaclev);
|
||
|
break; // Concatena i livelli
|
||
|
case F_MAGAZZINO:
|
||
|
_key.add(str);
|
||
|
row.get(i+1, str);
|
||
|
str.trim();
|
||
|
_key << str;
|
||
|
break; // Concatena magazzini e depositi
|
||
|
case F_CLIENTE:
|
||
|
if (str.blank()) str = "0";
|
||
|
case F_ARTICOLO:
|
||
|
case F_CODIMP:
|
||
|
case F_CODLIN:
|
||
|
_key.add(str); break; // Aggiungi normalmente
|
||
|
}
|
||
|
}
|
||
|
TSortable* s = create ? add_obj(_key) : find_obj(_key);
|
||
|
return (TMSP_line*)s;
|
||
|
}
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TPlan_docs
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
TSortable* TPlan_docs::new_obj(const TToken_string& key) const
|
||
|
{
|
||
|
int anno; key.get(0, anno);
|
||
|
long num; key.get(1, num);
|
||
|
|
||
|
TDocumento* doc = new TDocumento('D', anno, _num, num);
|
||
|
doc->head().put(DOC_TIPODOC, _doc);
|
||
|
return doc;
|
||
|
}
|
||
|
|
||
|
TDocumento& TPlan_docs::find(int anno, long num)
|
||
|
{
|
||
|
_key.format("%d|%ld", anno, num);
|
||
|
return *(TDocumento*)add_obj(_key);
|
||
|
}
|
||
|
|
||
|
TRiga_documento& TPlan_docs::add_to_row(int anno, long num, int riga, const real& qta)
|
||
|
{
|
||
|
TDocumento& doc = find(anno, num);
|
||
|
if (riga <= 0 || riga > doc.physical_rows())
|
||
|
{
|
||
|
TRiga_documento& r = doc.new_row(_rig);
|
||
|
riga = r.get_int(RDOC_NRIGA);
|
||
|
}
|
||
|
TRiga_documento& rdoc = doc[riga];
|
||
|
real val = rdoc.get(RDOC_QTA);
|
||
|
val += qta;
|
||
|
if (val <= ZERO)
|
||
|
rdoc.put(RDOC_QTA, ZERO);
|
||
|
else
|
||
|
rdoc.put(RDOC_QTA, val);
|
||
|
|
||
|
return rdoc;
|
||
|
}
|
||
|
|
||
|
long TPlan_docs::flush(const TDate& data)
|
||
|
{
|
||
|
const long tot = items();
|
||
|
long retv=tot;
|
||
|
if (tot > 0L)
|
||
|
{
|
||
|
TString msg;
|
||
|
msg << "Registrazione dei documenti di planning per il " << data;
|
||
|
TProgind pi(tot, msg, FALSE, TRUE);
|
||
|
TLocalisamfile lfdoc(LF_DOC);
|
||
|
for (long d = 0; d < tot; d++)
|
||
|
{
|
||
|
pi.addstatus(1);
|
||
|
TDocumento& doc = (TDocumento&)find_obj(d);
|
||
|
lfdoc.curr() = doc.head();
|
||
|
int err = lfdoc.read(_isequal, _lock);
|
||
|
if (err == _iskeynotfound || err == NOERR)
|
||
|
{
|
||
|
for (int r = doc.physical_rows(); r > 0; r--)
|
||
|
{
|
||
|
const TRiga_documento& riga = doc[r];
|
||
|
if (riga.is_articolo() && riga.quantita() == ZERO)
|
||
|
doc.destroy_row(r, TRUE);
|
||
|
}
|
||
|
if (doc.physical_rows())
|
||
|
err = (err == _iskeynotfound) ? doc.write(lfdoc) : doc.rewrite(lfdoc);
|
||
|
else
|
||
|
err = doc.remove(lfdoc);
|
||
|
}
|
||
|
if (err != NOERR)
|
||
|
{
|
||
|
error_box("Impossibile riscrivere il documento del %d %s %ld",doc.anno(), (const char *)doc.numerazione(),doc.numero());
|
||
|
retv=-1;
|
||
|
}
|
||
|
}
|
||
|
destroy();
|
||
|
}
|
||
|
return retv;
|
||
|
}
|
||
|
|
||
|
TPlan_docs::TPlan_docs(const char* num, const char* tip, const char* rig)
|
||
|
: _num(num), _doc(tip), _rig(rig)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool distinta_master(const char *code)
|
||
|
{
|
||
|
const TRectype &rec=cache().get(LF_DIST,code);
|
||
|
if (rec.empty())
|
||
|
return FALSE;
|
||
|
return rec.get_bool("MASTER");
|
||
|
}
|
||
|
|