1999-04-06 15:34:39 +00:00
# include <applicat.h>
2005-02-17 18:13:12 +00:00
# include <colmask.h>
# include <printer.h>
1999-04-06 15:34:39 +00:00
# include <progind.h>
# include <tabutil.h>
2001-07-24 13:28:55 +00:00
# include <urldefid.h>
2005-02-17 18:13:12 +00:00
# include <utility.h>
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
# include "..\mg\anamag.h"
1999-04-06 15:34:39 +00:00
# include "..\ve\veconf.h"
2006-07-11 13:10:51 +00:00
# include <anagr.h>
# include <nditte.h>
1999-04-06 15:34:39 +00:00
# include "mr2100.h"
# include "mr2100a.h"
1999-10-22 10:00:18 +00:00
# include "mr2100c.h"
1999-04-06 15:34:39 +00:00
2005-02-17 18:13:12 +00:00
///////////////////////////////////////////////////////////
// Utility
///////////////////////////////////////////////////////////
2006-07-11 13:10:51 +00:00
static bool is_production_article ( const TCodice_articolo & codart )
2005-02-17 18:13:12 +00:00
{
const TRectype & rec = cache ( ) . get ( LF_DIST , codart ) ;
bool art_prod = false ;
if ( rec . empty ( ) )
art_prod = cache ( ) . get ( LF_ANAMAG , codart ) . get_bool ( ANAMAG_ARTPROD ) ;
else
2006-07-11 13:10:51 +00:00
art_prod = rec . get_bool ( ANAMAG_ARTPROD ) ;
2005-02-17 18:13:12 +00:00
return art_prod ;
}
1999-04-06 15:34:39 +00:00
///////////////////////////////////////////////////////////
// TMRP_record
///////////////////////////////////////////////////////////
2006-07-11 13:10:51 +00:00
void TMRP_record : : add_ref ( TMRP_docref * ref , TMRP_docrefs * & refs )
1999-04-06 15:34:39 +00:00
{
2002-12-20 16:15:03 +00:00
if ( ref ! = NULL )
1999-10-22 10:00:18 +00:00
{
2002-12-20 16:15:03 +00:00
if ( refs = = NULL )
2006-07-11 13:10:51 +00:00
refs = new TMRP_docrefs ;
2002-12-20 16:15:03 +00:00
refs - > add ( ref ) ;
1999-10-22 10:00:18 +00:00
}
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_gross_req ( const real & val , TMRP_internalref * ref )
1999-10-22 10:00:18 +00:00
{
if ( _internal_req = = NULL )
2006-07-11 13:10:51 +00:00
_internal_req = new TMRP_internalrefs ;
1999-10-22 10:00:18 +00:00
_internal_req - > add ( ref ) ;
return add_gross_req ( val ) ;
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_gross_req ( const real & val , TMRP_docref * ref )
1999-10-22 10:00:18 +00:00
{
2002-12-20 16:15:03 +00:00
add_ref ( ref , _requirements ) ;
1999-04-06 15:34:39 +00:00
_gross_requirement + = val ;
return _gross_requirement ;
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_sched_rec ( const real & val , TMRP_docref * ref )
1999-04-06 15:34:39 +00:00
{
2002-12-20 16:15:03 +00:00
add_ref ( ref , _scheduls ) ;
1999-04-06 15:34:39 +00:00
_sched_receipts + = val ;
return _sched_receipts ;
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_planned_ord ( const real & val , TMRP_docref * ref )
1999-06-18 15:35:05 +00:00
{
2002-12-20 16:15:03 +00:00
add_ref ( ref , _plans ) ;
1999-06-18 15:35:05 +00:00
_planned_orders + = val ;
return _planned_orders ;
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_resched_ord ( const real & val )
1999-10-22 10:00:18 +00:00
{
_resched_orders + = val ;
return _resched_orders ;
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_unsched_ord ( const real & val )
1999-06-18 15:35:05 +00:00
{
1999-10-22 10:00:18 +00:00
_unsched_orders + = val ;
return _unsched_orders ;
1999-06-18 15:35:05 +00:00
}
2006-07-11 13:10:51 +00:00
const real & TMRP_record : : add_net_req ( const real & val )
1999-04-06 15:34:39 +00:00
{
_net_requirement + = val ;
return _net_requirement ;
}
TObject * TMRP_record : : dup ( ) const
{
TMRP_record * o = new TMRP_record ( _time ) ;
o - > TMRP_record : : operator = ( * this ) ;
return o ;
}
2006-07-11 13:10:51 +00:00
TMRP_record & TMRP_record : : operator = ( const TMRP_record & a )
1999-04-06 15:34:39 +00:00
{
_gross_requirement = a . _gross_requirement ;
_on_hand = a . _on_hand ;
_sched_receipts = a . _sched_receipts ;
_net_requirement = a . _net_requirement ;
_planned_orders = a . _planned_orders ;
1999-10-22 10:00:18 +00:00
_resched_orders = a . _resched_orders ;
if ( a . _plans ) _plans = ( TMRP_docrefs * ) a . _plans - > dup ( ) ;
if ( a . _scheduls ) _scheduls = ( TMRP_docrefs * ) a . _scheduls - > dup ( ) ;
if ( a . _requirements ) _requirements = ( TMRP_docrefs * ) a . _requirements - > dup ( ) ;
if ( a . _internal_req ) _internal_req = ( TMRP_internalrefs * ) a . _internal_req - > dup ( ) ;
1999-04-06 15:34:39 +00:00
return * this ;
}
2006-07-11 13:10:51 +00:00
TMRP_record : : TMRP_record ( const TMRP_time & t ) : _time ( t )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
_plans = NULL ;
_scheduls = NULL ;
_requirements = NULL ;
_internal_req = NULL ;
1999-04-06 15:34:39 +00:00
}
///////////////////////////////////////////////////////////
// TMRP_line
///////////////////////////////////////////////////////////
2006-07-11 13:10:51 +00:00
TArticolo_giacenza * TMRP_line : : _articolo_giac = NULL ;
2008-06-11 10:58:17 +00:00
// Stringa temporanea di lavoro
static TString16 _sub ;
const TString & TMRP_line : : codmag ( ) const
{ return _sub = _codmag . left ( 3 ) ; }
const TString & TMRP_line : : codmagaz_coll ( ) const
{ return _sub = _codmag_coll . left ( 3 ) ; }
const TString & TMRP_line : : coddep ( ) const
{ return _sub = _codmag . mid ( 3 ) ; }
const TString & TMRP_line : : coddep_coll ( ) const
{ return _sub = _codmag_coll . mid ( 3 ) ; }
2006-07-11 13:10:51 +00:00
const TString & TMRP_line : : livgiac ( int l ) const
{
const TCodgiac_livelli & lg = livelli_giacenza ( ) ;
2008-06-11 10:58:17 +00:00
return _sub = _livgiac . mid ( lg . code_start ( l ) - 1 , lg . code_length ( l ) ) ;
2006-07-11 13:10:51 +00:00
}
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
void TMRP_line : : lotti_riordino ( real & minimo , real & increm ) const
1999-04-06 15:34:39 +00:00
{
_articolo_giac - > read ( _codart ) ;
const int i = _articolo_giac - > find_mag ( " " , _codmag ) ;
if ( i > = 0 )
{
const TRectype & rec = _articolo_giac - > mag ( " " ) . row ( i ) ;
minimo = rec . get_real ( MAG_LOTTORIOR ) ;
increm = rec . get_real ( MAG_LOTTOIRIOR ) ;
} else
minimo = increm = 0 ;
if ( minimo . is_zero ( ) )
minimo = _articolo_giac - > get_real ( MAG_LOTTORIOR ) ;
if ( increm . is_zero ( ) )
increm = _articolo_giac - > get_real ( MAG_LOTTOIRIOR ) ;
}
int TMRP_line : : add_son ( const real & qta , TMRP_line * son )
{
CHECK ( son , " Can't add NULL TMRP_line son " ) ;
1999-10-22 10:00:18 +00:00
if ( son = = this )
2004-05-18 11:17:26 +00:00
fatal_box ( FR ( " Riga di MRP %sz %s padre di se stessa " ) , ( const char * ) articolo ( ) , ( const char * ) livgiac ( ) ) ;
1999-04-06 15:34:39 +00:00
CHECK ( son ! = this , " Hermafrodite TMRP_line " ) ;
_qta_sons . add ( qta ) ;
return _sons . add ( son ) ;
}
bool TMRP_line : : is_son ( const TCodice_articolo & art ) const
{
2007-01-03 17:23:36 +00:00
int i ;
for ( i = sons ( ) - 1 ; i > = 0 ; i - - )
1999-04-06 15:34:39 +00:00
{
const TMRP_line & r = son ( i ) ;
1999-10-22 10:00:18 +00:00
if ( r . articolo ( ) = = art )
1999-04-06 15:34:39 +00:00
break ;
}
return i > = 0 ;
}
int TMRP_line : : compare ( const TSortable & s ) const
{
const TMRP_line & line = ( const TMRP_line & ) s ;
const bool imfather = sons ( ) > 0 ;
const bool hesfather = line . sons ( ) > 0 ;
2007-09-17 15:33:04 +00:00
/*
1999-10-22 10:00:18 +00:00
if ( imfather & & ( ! hesfather | | is_son ( line . articolo ( ) ) ) )
1999-04-06 15:34:39 +00:00
return + 1 ;
1999-10-22 10:00:18 +00:00
if ( hesfather & & ( ! imfather | | line . is_son ( articolo ( ) ) ) )
1999-04-06 15:34:39 +00:00
return - 1 ;
return 0 ;
2007-09-17 15:33:04 +00:00
*/
if ( imfather & & ! hesfather )
return + 1 ;
if ( hesfather & & ! imfather )
return - 1 ;
int c = 0 ; // Non farti ingannare dalle distinte cicliche!
if ( is_son ( line . articolo ( ) ) ) c + + ;
if ( line . is_son ( articolo ( ) ) ) c - - ;
return c ;
1999-04-06 15:34:39 +00:00
}
TObject * TMRP_line : : dup ( ) const
{
2006-07-11 13:10:51 +00:00
TMRP_line * o = new TMRP_line ( * this ) ;
1999-04-06 15:34:39 +00:00
return o ;
}
2006-07-11 13:10:51 +00:00
TMRP_line & TMRP_line : : operator = ( const TMRP_line & a )
1999-04-06 15:34:39 +00:00
{
//key
_codart = a . _codart ;
_livgiac = a . _livgiac ;
_codmag = a . _codmag ;
_codimp = a . _codimp ;
_codlin = a . _codlin ;
1999-10-22 10:00:18 +00:00
_codclifor = a . _codclifor ;
2006-07-11 13:10:51 +00:00
_da_rdoc_key = a . _da_rdoc_key ;
1999-04-06 15:34:39 +00:00
// contents
1999-10-22 10:00:18 +00:00
_descr = a . _descr ;
1999-04-06 15:34:39 +00:00
_sons = a . _sons ;
_qta_sons = a . _qta_sons ;
_req_per_bucket = a . _req_per_bucket ;
2001-06-25 10:41:20 +00:00
_final_product = a . _final_product ;
2007-09-17 15:33:04 +00:00
_sheet_row = a . _sheet_row ;
1999-04-06 15:34:39 +00:00
_articolo_giac = new TArticolo_giacenza ( a . _articolo_giac - > codice ( ) ) ;
return * this ;
}
TMRP_record & TMRP_line : : record ( int i ) const
{
TMRP_record * rec = ( TMRP_record * ) _req_per_bucket . objptr ( i ) ;
1999-06-18 15:35:05 +00:00
CHECKD ( rec , " Invalid MRP record " , i ) ;
1999-04-06 15:34:39 +00:00
return * rec ;
}
TMRP_record & TMRP_line : : record ( const TMRP_time & t ) const
{
const int last = last_bucket ( ) ;
2007-01-03 17:23:36 +00:00
int i ;
for ( i = 0 ; i < = last ; i + + )
1999-04-06 15:34:39 +00:00
{
TMRP_record & rec = record ( i ) ;
const int cmp = rec . time ( ) . compare ( t ) ;
if ( cmp = = 0 )
return rec ;
if ( cmp > 0 )
{
( ( TArray & ) _req_per_bucket ) . insert ( NULL , i ) ;
break ;
}
}
TMRP_record * rec = new TMRP_record ( t ) ;
( ( TArray & ) _req_per_bucket ) . add ( rec , i ) ;
return * rec ;
}
// approssima in base al lotto minimo; prevede valori negativi
2000-10-03 13:45:12 +00:00
real TMRP_line : : sizeup_net_requirement ( int i , const real & val , const real & oldnet )
1999-04-06 15:34:39 +00:00
{
2000-10-03 13:45:12 +00:00
real req ( oldnet ) ; // Azzera net requirement
if ( val + oldnet < ZERO )
1999-04-06 15:34:39 +00:00
{
2000-10-03 13:45:12 +00:00
req = - ( val + oldnet ) ; // Rende positiva la richiesta effettiva
1999-04-06 15:34:39 +00:00
real lm , li ;
2000-10-03 13:45:12 +00:00
lotti_riordino ( lm , li ) ;
1999-04-06 15:34:39 +00:00
if ( req > lm ) // Se la richiesta supera il lotto minimo
{
if ( li > ZERO )
{
// Calcola il numero di lotti incrementali
real lotti = ( req - lm ) / li ;
lotti . ceil ( ) ;
// La quantita' richiesta = minimo + lotti * dim.lotti
req = lm + lotti * li ;
}
}
else
req = lm ; // Forza la richiesta almeno al lotto minimo
2000-10-03 13:45:12 +00:00
req + = oldnet ;
1999-04-06 15:34:39 +00:00
}
set_net_req ( i , req ) ;
return req ;
}
2006-07-11 13:10:51 +00:00
const real & TMRP_line : : add_gross_req ( const TMRP_time & t , const real & val , TMRP_internalref * ref )
1999-10-22 10:00:18 +00:00
{ return record ( t ) . add_gross_req ( val , ref ) ; }
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
const real & TMRP_line : : add_gross_req ( const TMRP_time & t , const real & val , TMRP_docref * ref )
1999-10-22 10:00:18 +00:00
{ return record ( t ) . add_gross_req ( val , ref ) ; }
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
const real & TMRP_line : : add_sched_rec ( const TMRP_time & t , const real & val , TMRP_docref * ref )
2000-05-05 15:25:49 +00:00
{ return record ( t ) . add_sched_rec ( val , ref ) ; }
1999-10-22 10:00:18 +00:00
2006-07-11 13:10:51 +00:00
const real & TMRP_line : : add_planned_ord ( const TMRP_time & t , const real & val , TMRP_docref * ref )
1999-10-22 10:00:18 +00:00
{ return record ( t ) . add_planned_ord ( val , ref ) ; }
const real & TMRP_line : : add_resched_ord ( int i , const real & val )
{ return record ( i ) . add_resched_ord ( val ) ; }
const real & TMRP_line : : add_unsched_ord ( int i , const real & val )
{ return record ( i ) . add_unsched_ord ( val ) ; }
1999-06-18 15:35:05 +00:00
1999-04-06 15:34:39 +00:00
const real & TMRP_line : : set_net_req ( int i , const real & val )
{
if ( val > ZERO )
return record ( i ) . set_net_req ( val ) ;
else
return record ( i ) . set_net_req ( ZERO ) ;
}
const real & TMRP_line : : add_net_req ( const TMRP_time & t , const real & val )
2000-05-05 15:25:49 +00:00
{ return record ( t ) . add_net_req ( val ) ; }
1999-04-06 15:34:39 +00:00
1999-06-18 15:35:05 +00:00
const real & TMRP_line : : add_net_req ( int i , const real & val )
{ return record ( i ) . add_net_req ( val ) ; }
1999-04-06 15:34:39 +00:00
const real & TMRP_line : : set_on_hand ( int i , const real & val )
{ return record ( i ) . set_on_hand ( val ) ; }
const real & TMRP_line : : set_on_hand ( const TMRP_time & t , const real & val )
{ return record ( t ) . set_on_hand ( val ) ; }
1999-06-18 15:35:05 +00:00
const TMRP_time & TMRP_line : : lead_time ( int i , TMRP_time & t , bool anticipate ) const
1999-04-06 15:34:39 +00:00
{
t = record ( i ) . time ( ) ;
1999-06-18 15:35:05 +00:00
if ( anticipate )
1999-04-06 15:34:39 +00:00
{
2005-05-16 23:44:23 +00:00
const TRectype & dist = cache ( ) . get ( LF_DIST , articolo ( ) ) ;
if ( ! dist . empty ( ) )
1999-06-18 15:35:05 +00:00
{
2005-05-16 23:44:23 +00:00
const int days = dist . get_int ( " LEADTIME " ) ;
const long hours = dist . get_long ( " LEADHOURS " ) ;
1999-06-18 15:35:05 +00:00
t . sub_time ( days , hours ) ;
}
else
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
_articolo_giac - > read ( articolo ( ) ) ;
TDate d = t . date ( ) ;
d - = _articolo_giac - > lead_time ( codmagdep ( ) , livgiac ( ) ) ;
t . set ( d , t . hour ( ) , t . impianto ( ) , t . linea ( ) ) ;
1999-04-06 15:34:39 +00:00
}
}
return t ;
}
2006-07-11 13:10:51 +00:00
real & TMRP_line : : giacenza_attuale ( real & g ) const
1999-04-06 15:34:39 +00:00
{
TDate d ( TODAY ) ;
return giacenza_attuale ( g , d ) ;
}
2001-05-02 13:40:49 +00:00
2006-07-11 13:10:51 +00:00
real & TMRP_line : : giacenza_attuale ( real & g , const TDate & d ) const
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
_articolo_giac - > read ( articolo ( ) ) ;
g = _articolo_giac - > giacenza_anno ( codmagdep ( ) , livgiac ( ) , d . year ( ) ) ;
1999-04-06 15:34:39 +00:00
return g ;
}
2006-07-11 13:10:51 +00:00
real & TMRP_line : : scorta_minima ( real & g ) const
1999-04-06 15:34:39 +00:00
{
TDate d ( TODAY ) ;
return scorta_minima ( g , d ) ;
}
2006-07-11 13:10:51 +00:00
real & TMRP_line : : scorta_minima ( real & g , const TDate & d ) const
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
_articolo_giac - > read ( articolo ( ) ) ;
g = _articolo_giac - > scorta_minima ( codmagdep ( ) , livgiac ( ) , d . year ( ) ) ;
1999-04-06 15:34:39 +00:00
return g ;
}
2005-02-17 18:13:12 +00:00
void TMRP_line : : set_imp_lin ( const char * imp , const char * lin )
{
_codimp = imp ;
_codlin = lin ;
2006-04-13 17:56:02 +00:00
if ( _codlin . full ( ) & & _codimp . full ( ) )
{
const TLinea_prod l ( _codlin ) ;
imp = l . codimp ( ) ;
if ( _codimp ! = imp )
{
# ifdef DBG
warning_box ( " Impianto '%s' incompatibile con la linea '%s': \n forzato a '%s'. " ,
2006-07-11 13:10:51 +00:00
( const char * ) _codimp , lin , imp ) ;
2006-04-13 17:56:02 +00:00
# endif
_codimp = imp ;
}
}
2005-02-17 18:13:12 +00:00
}
1999-04-06 15:34:39 +00:00
TMRP_line : : TMRP_line ( const char * art , const char * giac ,
2006-07-11 13:10:51 +00:00
const char * mag , const char * magc ,
const char * imp , const char * lin ,
long codcli , const char * da_rdoc_key )
2005-03-03 15:42:04 +00:00
: _codart ( art ) , _livgiac ( giac ) , _explosion_depth ( 0 ) ,
1999-06-18 15:35:05 +00:00
_codmag ( mag ) , _codmag_coll ( magc ) ,
2006-07-11 13:10:51 +00:00
_codclifor ( codcli ) , _da_rdoc_key ( da_rdoc_key ) ,
2007-09-17 15:33:04 +00:00
_final_product ( FALSE ) , _sheet_row ( NULL )
1999-04-06 15:34:39 +00:00
{
2006-04-13 17:56:02 +00:00
set_imp_lin ( imp , lin ) ;
2006-07-11 13:10:51 +00:00
if ( _articolo_giac = = NULL )
_articolo_giac = new TArticolo_giacenza ( ) ;
1999-04-06 15:34:39 +00:00
}
TMRP_line : : TMRP_line ( const TMRP_line & a )
{
TMRP_line : : operator = ( a ) ;
}
///////////////////////////////////////////////////////////
// TMRP_lines
///////////////////////////////////////////////////////////
TMRP_lines : : TMRP_lines ( const TMRP_lines & a )
{
TMRP_lines : : operator = ( a ) ;
}
TObject * TMRP_lines : : dup ( ) const
{
1999-10-22 10:00:18 +00:00
return new TMRP_lines ( * this ) ;
1999-04-06 15:34:39 +00:00
}
TMRP_lines & TMRP_lines : : operator = ( const TMRP_lines & a )
{
TMRP_array : : operator = ( a ) ;
_ignore_mag = a . _ignore_mag ;
1999-10-22 10:00:18 +00:00
_ignore_dep = a . _ignore_dep ;
1999-04-06 15:34:39 +00:00
_ignore_imp = a . _ignore_imp ;
_ignore_lin = a . _ignore_lin ;
2006-07-11 13:10:51 +00:00
_ignore_key = a . _ignore_key ;
1999-04-06 15:34:39 +00:00
return * this ;
}
1999-06-18 15:35:05 +00:00
TSortable * TMRP_lines : : new_obj ( const TToken_string & key ) const
{
TCodice_articolo art ; key . get ( 0 , art ) ; art . trim ( ) ;
TString16 gia ; key . get ( 1 , gia ) ; gia . trim ( ) ;
TString8 mag ; key . get ( 2 , mag ) ; mag . trim ( ) ;
TString8 magc ; key . get ( 3 , magc ) ; magc . trim ( ) ;
TString8 imp ; key . get ( 4 , imp ) ; imp . trim ( ) ;
TString8 lin ; key . get ( 5 , lin ) ; lin . trim ( ) ;
2006-07-11 13:10:51 +00:00
long clifor ; key . get ( 6 , clifor ) ;
TString da_rdoc_key ; key . get ( 7 , da_rdoc_key ) ;
return new TMRP_line ( art , gia , mag , magc , imp , lin , clifor , da_rdoc_key ) ;
1999-06-18 15:35:05 +00:00
}
TMRP_line * TMRP_lines : : find ( const TCodice_articolo & codart , const TString & gia ,
const TString & mag , const TString & magc ,
1999-04-06 15:34:39 +00:00
const TString & imp , const TString & lin ,
2006-07-11 13:10:51 +00:00
long codcli , const char * rdoc_key , bool create )
1999-04-06 15:34:39 +00:00
{
_key = codart ;
_key . add ( gia ) ;
1999-10-22 10:00:18 +00:00
_key . trim ( ) ; // trim to trim giaclevel...
1999-04-06 15:34:39 +00:00
if ( _ignore_mag )
1999-06-18 15:35:05 +00:00
{
1999-04-06 15:34:39 +00:00
_key . add ( " " , 2 ) ;
1999-06-18 15:35:05 +00:00
_key . add ( " " , 3 ) ;
}
1999-04-06 15:34:39 +00:00
else
1999-06-18 15:35:05 +00:00
{
1999-10-22 10:00:18 +00:00
if ( _ignore_dep )
{
_key . add ( mag . left ( 3 ) , 2 ) ;
_key . add ( magc . left ( 3 ) , 3 ) ;
2006-07-11 13:10:51 +00:00
}
else
{
1999-10-22 10:00:18 +00:00
_key . add ( mag , 2 ) ;
_key . add ( magc , 3 ) ;
}
1999-06-18 15:35:05 +00:00
}
2005-03-03 15:42:04 +00:00
if ( _ignore_imp | | imp . blank ( ) )
1999-06-18 15:35:05 +00:00
_key . add ( " " , 4 ) ;
1999-04-06 15:34:39 +00:00
else
1999-06-18 15:35:05 +00:00
_key . add ( imp , 4 ) ;
2005-03-03 15:42:04 +00:00
if ( _ignore_lin | | lin . blank ( ) )
1999-06-18 15:35:05 +00:00
_key . add ( " " , 5 ) ;
1999-04-06 15:34:39 +00:00
else
1999-06-18 15:35:05 +00:00
_key . add ( lin , 5 ) ;
_key . add ( codcli , 6 ) ;
2006-07-11 13:10:51 +00:00
if ( _ignore_key )
_key . add ( " " , 7 ) ;
else
_key . add ( rdoc_key , 7 ) ;
1999-04-06 15:34:39 +00:00
TSortable * s = create ? add_obj ( _key ) : find_obj ( _key ) ;
return ( TMRP_line * ) s ;
}
TMRP_lines : : TMRP_lines ( )
2006-07-11 13:10:51 +00:00
: _ignore_mag ( false ) , _ignore_dep ( false ) , _ignore_imp ( false ) ,
_ignore_lin ( false ) , _ignore_key ( true )
1999-04-06 15:34:39 +00:00
{ }
TMRP_lines : : ~ TMRP_lines ( )
{ destroy ( ) ; }
///////////////////////////////////////////////////////////
// TRiga_ordine
///////////////////////////////////////////////////////////
1999-10-22 10:00:18 +00:00
# define COMPARE_ALL_CODES 13 //
# define COMPARE_COMPLETE 99 //
# define COMPARE_TDFA -1 //
# define COMPARE_TDAF -2 //
# define COMPARE_TFAD -3 //
# define COMPARE_TFDA -4 //
# define COMPARE_TAFD -5 //
# define COMPARE_TADF -6 //
# define COMPARE_DTFA -7 // data documento + data di consegna + fornitore + articolo
# define COMPARE_DATF -8 // data documento + data di consegna + articolo + fornitore
# define COMPARE_ATFD -9 //
# define COMPARE_ADTF -10 //
2000-10-03 13:45:12 +00:00
# define COMPARE_TCFA -11 //
# define COMPARE_TCAF -12 //
# define COMPARE_TFAC -13 //
# define COMPARE_TFCA -14 //
# define COMPARE_TAFC -15 //
# define COMPARE_TACF -16 //
# define COMPARE_CTFA -17 // data di consegna + data documento + fornitore + articolo
# define COMPARE_CATF -18 // data di consegna + data documento + articolo + fornitore
# define COMPARE_ATFC -19 //
# define COMPARE_ACTF -20 //
1999-10-22 10:00:18 +00:00
1999-04-06 15:34:39 +00:00
class TRiga_ordine : public TToken_string
{
2006-07-11 13:10:51 +00:00
TRiga_ordine ( ) { CHECK ( false , " Miiii " ) ; }
1999-04-06 15:34:39 +00:00
public :
2006-07-11 13:10:51 +00:00
int compare ( const TToken_string & r , bool compare_orig_doc , int level = COMPARE_ALL_CODES , bool ascending = true ) const ;
1999-04-06 15:34:39 +00:00
int compare_field ( TString & str0 , TString & str1 , short field_no ) const ;
TRiga_ordine & operator = ( TToken_string & r ) ;
TRiga_ordine & operator + = ( TRiga_ordine & r ) ;
1999-10-22 10:00:18 +00:00
TRiga_ordine ( const TDate & datadoc , const TDate & datacons , long forn ,
const TMRP_line & line , int bucket , const real & price ) ;
1999-04-06 15:34:39 +00:00
virtual ~ TRiga_ordine ( ) { }
} ;
2006-07-11 13:10:51 +00:00
int TRiga_ordine : : compare ( const TToken_string & riga , bool compare_orig_doc , int level , bool ascending ) const
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
TString str0 , str1 ;
1999-04-06 15:34:39 +00:00
int cmp = 0 ;
if ( level > = 0 )
{
2007-01-03 17:23:36 +00:00
int i ;
for ( i = 2 ; i < = level & & i < = COMPARE_ALL_CODES & & cmp = = 0 ; i + + )
1999-04-06 15:34:39 +00:00
{
get ( i , str0 ) ;
riga . get ( i , str1 ) ;
1999-10-22 10:00:18 +00:00
cmp = compare_field ( str0 , str1 , short ( i + FIRST_FIELD ) ) ;
}
if ( level > COMPARE_ALL_CODES )
{
i = F_DOCANNODOC ;
while ( cmp = = 0 & & i < = F_DOCNRIGA )
{
get ( i - FIRST_FIELD , str0 ) ;
riga . get ( i - FIRST_FIELD , str1 ) ;
if ( str1 . blank ( ) ) // se la linea trovata non <20> riferita a un doc, va sempre bene
2006-07-11 13:10:51 +00:00
break ;
1999-10-22 10:00:18 +00:00
cmp = compare_field ( str0 , str1 , short ( i + + ) ) ;
}
1999-04-06 15:34:39 +00:00
}
2006-07-11 13:10:51 +00:00
1999-04-06 15:34:39 +00:00
} else {
// ordinamenti non standard
short f ;
1999-10-22 10:00:18 +00:00
short fields_TFAD [ ] = { F_ORD_TYPE , F_FORNITORE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_DATADOC , F_DATACONS } ;
short fields_TFDA [ ] = { F_ORD_TYPE , F_FORNITORE , F_DATADOC , F_DATACONS , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 } ;
short fields_TDFA [ ] = { F_ORD_TYPE , F_DATADOC , F_DATACONS , F_FORNITORE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 } ;
short fields_TDAF [ ] = { F_ORD_TYPE , F_DATADOC , F_DATACONS , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_FORNITORE } ;
short fields_TAFD [ ] = { F_ORD_TYPE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_FORNITORE , F_DATADOC , F_DATACONS } ;
short fields_TADF [ ] = { F_ORD_TYPE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_DATADOC , F_DATACONS , F_FORNITORE } ;
short fields_DTFA [ ] = { F_DATADOC , F_DATACONS , F_ORD_TYPE , F_FORNITORE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 } ;
short fields_DATF [ ] = { F_DATADOC , F_DATACONS , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_ORD_TYPE , F_FORNITORE } ;
short fields_ATFD [ ] = { F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_ORD_TYPE , F_FORNITORE , F_DATADOC , F_DATACONS } ;
short fields_ADTF [ ] = { F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_ORD_TYPE , F_DATADOC , F_DATACONS , F_FORNITORE } ;
2000-10-03 13:45:12 +00:00
short fields_TFAC [ ] = { F_ORD_TYPE , F_FORNITORE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_DATACONS , F_DATADOC } ;
short fields_TFCA [ ] = { F_ORD_TYPE , F_FORNITORE , F_DATACONS , F_DATADOC , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 } ;
short fields_TCFA [ ] = { F_ORD_TYPE , F_DATACONS , F_DATADOC , F_FORNITORE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 } ;
short fields_TCAF [ ] = { F_ORD_TYPE , F_DATACONS , F_DATADOC , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_FORNITORE } ;
short fields_TAFC [ ] = { F_ORD_TYPE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_FORNITORE , F_DATACONS , F_DATADOC } ;
short fields_TACF [ ] = { F_ORD_TYPE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_DATACONS , F_DATADOC , F_FORNITORE } ;
short fields_CTFA [ ] = { F_DATACONS , F_DATADOC , F_ORD_TYPE , F_FORNITORE , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 } ;
short fields_CATF [ ] = { F_DATACONS , F_DATADOC , F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_ORD_TYPE , F_FORNITORE } ;
short fields_ATFC [ ] = { F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_ORD_TYPE , F_FORNITORE , F_DATACONS , F_DATADOC } ;
short fields_ACTF [ ] = { F_ARTICOLO , F_LIV1 , F_LIV2 , F_LIV3 , F_LIV4 , F_ORD_TYPE , F_DATACONS , F_DATADOC , F_FORNITORE } ;
1999-10-22 10:00:18 +00:00
for ( int i = 0 ; i < 9 & & cmp = = 0 ; i + + )
1999-04-06 15:34:39 +00:00
{
switch ( level )
{
1999-10-22 10:00:18 +00:00
case COMPARE_TFAD : f = fields_TFAD [ i ] ; break ;
case COMPARE_TFDA : f = fields_TFDA [ i ] ; break ;
case COMPARE_TDFA : f = fields_TDFA [ i ] ; break ;
case COMPARE_TDAF : f = fields_TDAF [ i ] ; break ;
case COMPARE_TADF : f = fields_TADF [ i ] ; break ;
case COMPARE_TAFD : f = fields_TAFD [ i ] ; break ;
case COMPARE_DTFA : f = fields_DTFA [ i ] ; break ;
case COMPARE_DATF : f = fields_DATF [ i ] ; break ;
case COMPARE_ADTF : f = fields_ADTF [ i ] ; break ;
case COMPARE_ATFD : f = fields_ATFD [ i ] ; break ;
2000-10-03 13:45:12 +00:00
case COMPARE_TFAC : f = fields_TFAC [ i ] ; break ;
case COMPARE_TFCA : f = fields_TFCA [ i ] ; break ;
case COMPARE_TCFA : f = fields_TCFA [ i ] ; break ;
case COMPARE_TCAF : f = fields_TCAF [ i ] ; break ;
case COMPARE_TACF : f = fields_TACF [ i ] ; break ;
case COMPARE_TAFC : f = fields_TAFC [ i ] ; break ;
case COMPARE_CTFA : f = fields_CTFA [ i ] ; break ;
case COMPARE_CATF : f = fields_CATF [ i ] ; break ;
case COMPARE_ACTF : f = fields_ACTF [ i ] ; break ;
case COMPARE_ATFC : f = fields_ATFC [ i ] ; break ;
1999-04-06 15:34:39 +00:00
default :
NFCHECK ( " Ordinamento sconosciuto " ) ;
break ;
}
1999-10-22 10:00:18 +00:00
get ( f - FIRST_FIELD , str0 ) ;
riga . get ( f - FIRST_FIELD , str1 ) ;
1999-04-06 15:34:39 +00:00
cmp = compare_field ( str0 , str1 , f ) ;
}
}
2006-07-11 13:10:51 +00:00
if ( compare_orig_doc )
{
int i = F_DAANNO ;
while ( cmp = = 0 & & i < = F_DANRIGA )
{
get ( i - FIRST_FIELD , str0 ) ;
riga . get ( i - FIRST_FIELD , str1 ) ;
cmp = compare_field ( str0 , str1 , short ( i + + ) ) ;
}
}
1999-06-18 15:35:05 +00:00
return ascending ? cmp : - cmp ;
1999-04-06 15:34:39 +00:00
}
int TRiga_ordine : : compare_field ( TString & str0 , TString & str1 , short field_no ) const
{
int cmp ;
switch ( field_no )
{
case F_DATADOC :
case F_DATACONS :
{
if ( str0 ! = str1 )
{
const TDate mine ( str0 ) ;
const TDate his ( str1 ) ;
cmp = mine > his ? + 1 : - 1 ;
}
else
cmp = 0 ;
}
break ;
case F_FORNITORE : // data doc
{
const long f0 = atol ( str0 ) ;
const long f1 = atol ( str1 ) ;
cmp = f0 = = f1 ? 0 : ( f0 > f1 ? + 1 : - 1 ) ;
}
break ;
default :
cmp = str0 . compare ( str1 ) ;
break ;
}
return cmp ;
}
TRiga_ordine & TRiga_ordine : : operator = ( TToken_string & r )
{
this - > TToken_string : : operator = ( r ) ;
return * this ;
}
TRiga_ordine & TRiga_ordine : : operator + = ( TRiga_ordine & r )
{
2006-07-11 13:10:51 +00:00
// CHECK(compare(r) == 0, "Can't add incompatible order line");
2002-12-20 16:15:03 +00:00
const real q = r . get ( F_QUANTITA - FIRST_FIELD ) ;
if ( ! q . is_zero ( ) )
{
real qta = get ( F_QUANTITA - FIRST_FIELD ) ;
qta + = q ; qta . round ( 5 ) ;
add ( qta . is_zero ( ) ? " " : qta . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
}
1999-04-06 15:34:39 +00:00
return * this ;
}
2002-12-20 16:15:03 +00:00
TRiga_ordine : : TRiga_ordine ( const TDate & datadoc , const TDate & datacons , long forn , const TMRP_line & line , int bucket , const real & price )
1999-04-06 15:34:39 +00:00
: TToken_string ( 128 )
2006-07-11 13:10:51 +00:00
1999-04-06 15:34:39 +00:00
{
2002-12-20 16:15:03 +00:00
// Determino il tipo di ordine (PROD/ACQ)
const TCodice_articolo & codart = line . articolo ( ) ;
2005-02-17 18:13:12 +00:00
const bool art_prod = is_production_article ( codart ) ;
2002-12-20 16:15:03 +00:00
1999-10-22 10:00:18 +00:00
add ( " " , F_SELECTED - FIRST_FIELD ) ;
2002-12-20 16:15:03 +00:00
add ( art_prod ? " P " : " F " , F_ORD_TYPE - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
add ( datadoc . string ( ) , F_DATADOC - FIRST_FIELD ) ;
add ( datacons . string ( ) , F_DATACONS - FIRST_FIELD ) ;
add ( line . codclifor ( ) ? line . codclifor ( ) : forn , F_FORNITORE - FIRST_FIELD ) ;
2005-02-17 18:13:12 +00:00
add ( codart , F_ARTICOLO - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
for ( int l = livelli_giacenza ( ) . last_level ( ) ; l > = 1 ; l - - )
add ( line . livgiac ( l ) , F_LIV1 + l - 1 - FIRST_FIELD ) ;
add ( line . codmag ( ) , F_MAGAZZINO - FIRST_FIELD ) ;
add ( line . coddep ( ) , F_DEPOSITO - FIRST_FIELD ) ;
add ( line . codimp ( ) , F_CODIMP - FIRST_FIELD ) ;
add ( line . codlin ( ) , F_CODLIN - FIRST_FIELD ) ;
real q = line . net_requirement ( bucket ) ;
//q -= line.planned_orders(bucket);
const TCodice_um um_nulla ;
const TQuantita qta ( line . articolo ( ) , um_nulla , q ) ;
2000-05-05 15:25:49 +00:00
if ( ! q . is_zero ( ) ) // cosi' non ci sono inestetici 0.0000 sulla maschera
add ( qta . val ( ) . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
add ( qta . um ( ) , F_UM - FIRST_FIELD ) ;
add ( price . string ( ) , F_PREZZO - FIRST_FIELD ) ;
1999-04-06 15:34:39 +00:00
1999-10-22 10:00:18 +00:00
add ( line . description ( ) , F_DESCART - FIRST_FIELD ) ;
}
1999-04-06 15:34:39 +00:00
1999-10-22 10:00:18 +00:00
///////////////////////////////////////////////////////////
// TMRP_docref / TMRP_docrefs
///////////////////////////////////////////////////////////
2005-03-03 15:42:04 +00:00
const TRectype & TMRP_docref : : get_doc ( ) const
2000-05-05 15:25:49 +00:00
{
2005-03-03 15:42:04 +00:00
TToken_string key ;
key . add ( " D " ) ;
key . add ( _annodoc ) ;
key . add ( _codnum ) ;
key . add ( _numdoc ) ;
return cache ( ) . get ( LF_DOC , key ) ;
2000-05-05 15:25:49 +00:00
}
2005-03-03 15:42:04 +00:00
const TRectype & TMRP_docref : : get_rdoc ( ) const
2000-05-05 15:25:49 +00:00
{
2005-03-03 15:42:04 +00:00
TToken_string key ;
key . add ( _codnum ) ;
key . add ( _annodoc ) ;
key . add ( " D " ) ;
key . add ( _numdoc ) ;
key . add ( _numrig ) ;
return cache ( ) . get ( LF_RIGHEDOC , key ) ;
2000-05-05 15:25:49 +00:00
}
2006-07-11 13:10:51 +00:00
TDate TMRP_docref : : datadoc ( ) const
2000-05-05 15:25:49 +00:00
{
2006-07-11 13:10:51 +00:00
return get_doc ( ) . get_date ( DOC_DATADOC ) ;
2000-05-05 15:25:49 +00:00
}
2006-07-11 13:10:51 +00:00
TDate TMRP_docref : : datacons ( ) const
2000-05-05 15:25:49 +00:00
{
2006-07-11 13:10:51 +00:00
TDate d ;
2000-05-05 15:25:49 +00:00
d = get_rdoc ( ) . get_date ( RDOC_DATACONS ) ;
if ( ! d . ok ( ) )
d = get_doc ( ) . get_date ( DOC_DATACONS ) ;
return d ;
}
2006-07-11 13:10:51 +00:00
2000-05-05 15:25:49 +00:00
const TString & TMRP_docref : : tipodoc ( )
{
2006-07-11 13:10:51 +00:00
static TString4 s ;
2000-05-05 15:25:49 +00:00
return s = get_doc ( ) . get ( DOC_TIPODOC ) ;
}
char TMRP_docref : : statodoc ( )
{
return get_doc ( ) . get_char ( DOC_STATO ) ;
}
1999-10-22 10:00:18 +00:00
TMRP_docref : : TMRP_docref ( int anno , const char * codnum , long numdoc , int nriga ,
const char * um , const real & qta , const real & prz )
{
_annodoc = anno ;
_codnum = codnum ;
_numdoc = numdoc ;
_numrig = nriga ;
_um = um ;
_qta = qta ;
_prz = prz ;
}
TObject * TMRP_docref : : dup ( ) const
{
TMRP_docref * o = new TMRP_docref ( _annodoc , _codnum , _numdoc , _numrig , _um , _qta , _prz ) ;
return o ;
}
TObject * TMRP_internalref : : dup ( ) const
{
TMRP_internalref * o = new TMRP_internalref ( * this ) ;
return o ;
}
TMRP_internalref : : TMRP_internalref ( TMRP_line * line , int bucket , const real & qta ) :
_line ( line ) , _qta ( qta ) , _bucket ( bucket )
{
_um = cache ( ) . get ( LF_DIST , line - > articolo ( ) ) . get ( " UM " ) ;
_date = _line - > record ( bucket ) . time ( ) . date ( ) ;
}
TMRP_internalref : : TMRP_internalref ( const TMRP_internalref & r ) :
_line ( r . _line ) , _qta ( r . _qta ) , _date ( r . _date ) , _um ( r . _um ) , _bucket ( r . _bucket )
{ }
TObject * TMRP_docrefs : : dup ( ) const
{
TMRP_docrefs * o = new TMRP_docrefs ( ) ;
* o = * this ;
return o ;
1999-04-06 15:34:39 +00:00
}
///////////////////////////////////////////////////////////
// TLav_finder Trova la prima lavorazione di un articolo
///////////////////////////////////////////////////////////
class TLav_finder : public TAssoc_array
{
TDecoder _lnp ;
bool _keep_imp ;
public :
void init ( bool ki = TRUE ) ;
const TString & lin2imp ( const TString & lin ) ;
TLavorazione & art2lav ( const TCodice_articolo & art ) ;
void art2magimpline ( const TCodice_articolo & art ,
TString & mag , TString & imp ,
TString & lin ) ;
TLav_finder ( ) ;
virtual ~ TLav_finder ( ) { }
} ;
void TLav_finder : : init ( bool ki )
{
_keep_imp = ki ;
TAssoc_array : : destroy ( ) ;
_lnp . destroy ( ) ;
}
TLavorazione & TLav_finder : : art2lav ( const TCodice_articolo & art )
{
TLavorazione * lav = ( TLavorazione * ) objptr ( art ) ;
if ( lav = = NULL )
{
TDistinta_tree tree ;
TArray boom ;
tree . set_root ( art ) ;
tree . explode ( boom , FALSE , RAGGR_EXP_UMBASE , 1 , " L " ) ;
2002-07-02 16:21:23 +00:00
TString80 codlav ;
1999-04-06 15:34:39 +00:00
if ( boom . items ( ) > 0 )
codlav = ( ( TRiga_esplosione & ) boom [ 0 ] ) . articolo ( ) ;
lav = new TLavorazione ( codlav ) ;
add ( art , lav ) ;
}
return * lav ;
}
void TLav_finder : : art2magimpline ( const TCodice_articolo & art ,
TString & mag , TString & imp ,
TString & lin )
{
TLavorazione & lav = art2lav ( art ) ;
2006-04-13 17:56:02 +00:00
if ( imp . blank ( ) & & lin . full ( ) )
1999-04-06 15:34:39 +00:00
imp = _lnp . decode ( lin ) ;
lin . cut ( 0 ) ;
const int ll = _keep_imp ? lav . linee ( ) : lav . linee_standard ( ) ;
for ( int l = 0 ; l < ll ; l + + )
{
const TString & linea = lav . cod_linea ( l ) ;
const bool goodimp = imp . empty ( ) | | _lnp . decode ( linea ) = = imp ;
if ( l = = 0 | | goodimp )
{ lin = linea ; lin . trim ( ) ; }
if ( goodimp )
break ;
}
2006-04-13 17:56:02 +00:00
if ( lin . full ( ) )
1999-04-06 15:34:39 +00:00
{
const TLinea_prod lnp ( lin ) ;
imp = lnp . codimp ( ) ;
1999-10-22 10:00:18 +00:00
mag = lnp . codmagdep ( ) ;
1999-04-06 15:34:39 +00:00
}
else
{
if ( ! _keep_imp )
imp = mag = " " ;
}
}
TLav_finder : : TLav_finder ( ) : _lnp ( " LNP " , " S6 " ) , _keep_imp ( TRUE )
{ }
///////////////////////////////////////////////////////////
// TMatResPlanning
///////////////////////////////////////////////////////////
1999-10-22 10:00:18 +00:00
class TMatResMask : public TCalendar_mask
{
TCondizione_vendita * _condv ;
1999-04-06 15:34:39 +00:00
2001-07-24 13:28:55 +00:00
TSelect_color_mask _sel_color ;
int _nodist_pos ;
1999-10-22 10:00:18 +00:00
void clear_sheets ( ) ;
2000-05-05 15:25:49 +00:00
int num_orders ( ) ;
1999-10-22 10:00:18 +00:00
void round_field ( TMask_field & fld , bool up ) const ;
virtual bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) ;
int find_pos ( const TRiga_ordine & r , int & cmp , int level = COMPARE_ALL_CODES ) const ;
void sort_orders ( ) ;
bool orders_selected ( char type , const char * dacatmer , const char * acatmer ) ;
void select_orders ( char type , const char * dacatmer , const char * acatmer ) ;
public :
2000-05-05 15:25:49 +00:00
1999-10-22 10:00:18 +00:00
int round_date ( TDate & date , bool up = FALSE ) const ;
int add_order_line ( long forn , const TMRP_line & l , int bucket ) ;
2001-07-24 13:28:55 +00:00
TSelect_color_mask & sel ( ) { return _sel_color ; }
1999-10-22 10:00:18 +00:00
TMatResMask ( ) ;
virtual ~ TMatResMask ( ) { }
} ;
1999-04-06 15:34:39 +00:00
class TMatResPlanning : public TSkeleton_application
{
TMRP_lines _articles ;
TLav_finder _artinfo ;
1999-10-22 10:00:18 +00:00
TMatResMask * _mask ;
1999-04-06 15:34:39 +00:00
private :
2001-05-02 13:40:49 +00:00
bool gross2net_logic ( TMRP_line & curr_article , int bucket , bool & sc_used ) ;
1999-10-22 10:00:18 +00:00
bool load_gross_requirements ( ) ;
bool load_planned_orders ( ) ;
2008-06-11 10:58:17 +00:00
bool ciclica ( TDistinta_tree & distinta ) ;
1999-10-22 10:00:18 +00:00
bool explode_articles ( ) ;
1999-04-06 15:34:39 +00:00
2006-04-13 17:56:02 +00:00
bool test_codnum ( const TCodice_numerazione & num , const TString_array & a ) const ;
2009-02-14 17:13:09 +00:00
bool test_codnum ( const TString & codnum , const TString_array & a ) const ;
2006-04-13 17:56:02 +00:00
int test_status ( const TRectype & doc , const TString_array & a ) const ;
bool has_confirmed_status ( const TRectype & doc , const TToken_string & riga ) const ;
1999-04-06 15:34:39 +00:00
protected :
1999-10-22 10:00:18 +00:00
bool preprocess_cycle ( ) ; // req iniziale dai docs
bool net_requirement_cycle ( ) ;
bool build_orders ( ) ;
2000-05-05 15:25:49 +00:00
static void print_except_header ( TPrinter & pr ) ;
1999-10-22 10:00:18 +00:00
static void print_orders_header ( TPrinter & pr ) ;
static void print_orders_body ( TPrinter & pr , TToken_string * sheetrow ) ;
static void set_body_order_line ( TPrintrow & row , TToken_string * sheetrow ) ;
2005-03-03 15:42:04 +00:00
TMRP_line * find_risalita_line ( TToken_string & row ) ;
const TRectype * irefs2rdoc ( const TMRP_internalrefs & iref ) const ;
1999-10-22 10:00:18 +00:00
bool print_risalita ( TToken_string & row , int backlevel , bool dett_ord ) ;
bool print_risalita ( const TMRP_line & line , const TDate & d , int backlevel , bool dett_ord ) ;
int print_internal_ref ( const TMRP_internalref & iref , int backlevel , bool dett_ord ) ;
int print_gross_ref ( const TMRP_line & line , int bucket ) ;
2000-05-05 15:25:49 +00:00
void print_exceptions ( TExceptions_array & excepts ) ;
bool print_exceptions ( TMask & m ) ;
bool print_planning ( TMask & m ) ;
2000-10-03 13:45:12 +00:00
bool ask_save ( ) ;
void save_orders ( TAssoc_array & docs ) ;
2005-05-16 23:44:23 +00:00
long compute_production_time ( const TMRP_line & line , const real & qta ) const ;
2006-07-11 13:10:51 +00:00
const TRectype * trova_da_rdoc ( const TMRP_line & line , const TDate & datacon ) const ;
2000-05-05 15:25:49 +00:00
1999-04-06 15:34:39 +00:00
public :
2001-07-24 13:28:55 +00:00
virtual bool menu ( MENU_TAG mt ) ;
1999-04-06 15:34:39 +00:00
virtual void main_loop ( ) ;
virtual bool firm_change_enabled ( ) const { return FALSE ; }
1999-10-22 10:00:18 +00:00
void compute ( ) ;
bool print_orders ( ) ;
bool emit_orders ( ) ;
void risalita ( const TMask & m ) ;
int round_date ( TDate & d , bool up = FALSE ) const { return _mask - > round_date ( d , up ) ; }
1999-04-06 15:34:39 +00:00
} ;
TMatResPlanning & app ( ) { return ( TMatResPlanning & ) main_app ( ) ; }
///////////////////////////////////////////////////////////
2006-07-11 13:10:51 +00:00
// TRisalita_mask
1999-04-06 15:34:39 +00:00
///////////////////////////////////////////////////////////
1999-10-22 10:00:18 +00:00
class TRisalita_mask : public TAutomask
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
TMRP_line * _line ;
bool add_total_row ( int pos , const char * um , const real & lordo , const char * umpadre , const real & lordopadre ) ;
1999-04-06 15:34:39 +00:00
protected :
virtual bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) ;
1999-10-22 10:00:18 +00:00
bool add_total_rows ( ) ;
2006-07-11 13:10:51 +00:00
static int compare_rows ( TSheet_field & sf , int r1 , int r2 ) ;
1999-04-06 15:34:39 +00:00
public :
1999-10-22 10:00:18 +00:00
int add_gross_ref ( const TMRP_line & line , int bucket ) ;
int add_internal_ref ( const TMRP_internalref & iref ) ;
2000-05-05 15:25:49 +00:00
TRisalita_mask ( TMRP_line * line , const TDate & from , const TDate & to , bool is_buck0 , int extraleadtime ) ;
1999-10-22 10:00:18 +00:00
virtual ~ TRisalita_mask ( ) { }
1999-04-06 15:34:39 +00:00
} ;
int TMatResMask : : round_date ( TDate & date , bool up ) const
{
1999-10-22 10:00:18 +00:00
// Dimensione del bucket in giorni
const int bucket_size = get_int ( F_BUCKET ) * get_int ( F_DAYXBUCK ) ;
1999-04-06 15:34:39 +00:00
// Riporta la data al primo lunedi prima dell'inizio
1999-06-18 15:35:05 +00:00
TDate inizio = get_date ( F_DADATA ) ;
1999-10-22 10:00:18 +00:00
int bucket ;
if ( bucket_size = = 31 ) // mese solare
1999-06-18 15:35:05 +00:00
{
1999-10-22 10:00:18 +00:00
if ( up )
{
date . set_end_month ( ) ;
int wday = date . wday ( ) ;
wday = ( 7 - wday ) % 7 ;
//wday -= get_int(F_LASTWRKDAY);
if ( wday < 0 )
date + = wday ;
}
else
date . set_day ( 1 ) ;
bucket = ( date . year ( ) - inizio . year ( ) ) * 12 + date . month ( ) - inizio . month ( ) ;
if ( bucket < 0 ) bucket = - 1 ;
1999-06-18 15:35:05 +00:00
}
else
1999-10-22 10:00:18 +00:00
{
if ( bucket_size > 1 ) // non vado a giorni
{
const int wday = inizio . wday ( ) ;
if ( wday > 1 ) inizio - = wday - 1 ;
}
// Calcola il bucket di appartenenza
const int days = int ( date - inizio ) ;
if ( days < 0 )
bucket = 0 ;
else
bucket = days / bucket_size ;
if ( up ) // Arrotonda alla fine del bucket
date = inizio + long ( ( bucket + 1 ) * bucket_size - 1 /*- get_int(F_LASTWRKDAY)*/ ) ;
else // Arrotonda all'inizio del bucket
date = inizio + long ( bucket * bucket_size ) ;
}
1999-04-06 15:34:39 +00:00
return bucket ;
}
void TMatResMask : : round_field ( TMask_field & fld , bool up ) const
{
TDate date = fld . get ( ) ;
if ( date . ok ( ) )
{
round_date ( date , up ) ;
fld . set ( date ) ;
}
}
2000-05-05 15:25:49 +00:00
int TMatResMask : : num_orders ( )
{
2006-07-11 13:10:51 +00:00
int n = 0 ;
2000-05-05 15:25:49 +00:00
TSheet_field & s = sfield ( F_ORDINI ) ;
FOR_EACH_SHEET_ROW_BACK ( s , r , row )
if ( ! real ( row - > get ( F_QUANTITA - FIRST_FIELD ) ) . is_zero ( ) )
n + + ;
return n ;
}
1999-04-06 15:34:39 +00:00
bool TMatResMask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
2004-05-18 11:17:26 +00:00
const char * confirm_msg = FR ( " Le attuali %d righe di ordine verranno perse. Confermare? " ) ;
1999-04-06 15:34:39 +00:00
switch ( o . dlg ( ) )
{
case F_DADATA :
if ( e = = fe_modify )
round_field ( o , FALSE ) ;
break ;
case F_ADATA :
if ( e = = fe_modify )
round_field ( o , TRUE ) ;
break ;
case F_BUCKET :
1999-10-22 10:00:18 +00:00
case F_DAYXBUCK :
1999-04-06 15:34:39 +00:00
if ( e = = fe_modify )
{
round_field ( field ( F_DADATA ) , FALSE ) ;
round_field ( field ( F_ADATA ) , TRUE ) ;
}
break ;
case F_NUM_ORC :
case F_TIPI_ORC :
case F_NUM_ORF :
case F_TIPI_ORF :
if ( e = = fe_init )
{
TSheet_field & s = ( TSheet_field & ) o ;
if ( s . items ( ) = = 0 )
{
s . row ( 0 ) ;
s . force_update ( ) ;
}
}
if ( e = = fe_close )
{
const TSheet_field & s = ( const TSheet_field & ) o ;
FOR_EACH_SHEET_ROW_BACK ( s , r , row )
if ( ! row - > empty_items ( ) ) return TRUE ;
2004-05-18 11:17:26 +00:00
return error_box ( TR ( " E' necessario inserire almeno una riga " ) ) ;
1999-04-06 15:34:39 +00:00
}
break ;
case F_ORDINI :
{
TSheet_field & s = ( TSheet_field & ) o ;
switch ( e )
{
case se_query_add :
return FALSE ;
default :
break ;
}
}
break ;
1999-10-22 10:00:18 +00:00
case F_FORNITORE :
if ( jolly = = 5 ) // codice fornitore sullo sheet ordini
{
TSheet_field & so = sfield ( F_ORDINI ) ;
TToken_string & row = so . row ( so . selected ( ) ) ;
switch ( e )
{
case fe_modify :
case fe_init :
{
real qta , price ;
TString codart ;
long codfor ;
char tipocf ;
row . get ( F_FORNITORE - FIRST_FIELD , codfor ) ;
row . get ( F_ORD_TYPE - FIRST_FIELD , tipocf ) ;
if ( tipocf = = ' F ' )
if ( codfor = = 0L )
{
}
else
{
row . get ( F_QUANTITA - FIRST_FIELD , qta ) ;
row . get ( F_ARTICOLO - FIRST_FIELD , codart ) ;
find_price ( get ( F_TIPOCV ) , get ( F_CODCONDV ) , get ( F_CATVEN_CV ) ,
" F " , codfor , codart , qta , price ) ;
row . add ( price . string ( ) , F_PREZZO - FIRST_FIELD ) ;
}
}
break ;
}
}
break ;
1999-04-06 15:34:39 +00:00
case F_YEAR :
case F_IMPIANTO :
case F_LINEA :
if ( e = = fe_modify | | ( o . dlg ( ) = = F_YEAR & & e = = fe_init ) )
update_calendar ( F_CALENDAR , F_YEAR , F_IMPIANTO , F_LINEA ) ;
break ;
1999-10-22 10:00:18 +00:00
case DLG_QUIT :
if ( e = = fe_button & & jolly = = 0L )
{
2000-05-05 15:25:49 +00:00
const int it = num_orders ( ) ;
1999-10-22 10:00:18 +00:00
if ( it > 0 & & ! yesno_box ( confirm_msg , it ) )
return FALSE ;
}
break ;
1999-04-06 15:34:39 +00:00
case DLG_CANCEL :
if ( e = = fe_button )
if ( jolly = = 0L )
{
TSheet_field & s = sfield ( F_ORDINI ) ;
const int it = s . items ( ) ;
if ( it = = 0 | | yesno_box ( confirm_msg , it ) )
{
enable ( - 1 ) ;
s . destroy ( ) ;
s . force_update ( ) ;
} else
return FALSE ;
}
break ;
case DLG_ELABORA :
if ( e = = fe_button & & check_fields ( ) )
{
TSheet_field & s = sfield ( F_ORDINI ) ;
const int it = s . items ( ) ;
if ( it = = 0 | | yesno_box ( confirm_msg , it ) )
{
s . destroy ( ) ;
1999-10-22 10:00:18 +00:00
app ( ) . compute ( ) ;
2000-05-05 15:25:49 +00:00
enable ( DLG_SAVEREC , s . items ( ) > 0 & & ! get_bool ( F_DISABLESAVE ) ) ;
1999-10-22 10:00:18 +00:00
enable ( - G_PREPROCESS , s . items ( ) = = 0 ) ;
1999-04-06 15:34:39 +00:00
sort_orders ( ) ;
s . set_focus ( ) ;
2005-02-17 18:13:12 +00:00
// Controlla se e' stato richiesto il salvataggio automatico e se posso salvare
if ( app ( ) . argc ( ) > = 2 & & field ( DLG_SAVEREC ) . active ( ) )
{
TString param = app ( ) . argv ( 2 ) ;
param . upper ( ) ;
if ( param . find ( " AUTOR " ) > 0 ) // Lancia salvataggio batch
{
app ( ) . emit_orders ( ) ;
stop_run ( K_FORCE_CLOSE ) ;
}
}
1999-04-06 15:34:39 +00:00
}
}
break ;
1999-10-22 10:00:18 +00:00
case F_RISALITA :
if ( e = = fe_button )
{
/*TSheet_field & sf= m.sfield(F_ORDINI);
TToken_string & row = sf . row ( sf . selected ( ) ) ;
TDate datacons ( row . get ( sf . cid2index ( F_DATACONS ) ) ) ; */
app ( ) . risalita ( * this ) ;
}
break ;
1999-06-18 15:35:05 +00:00
case F_RESORT_ORDINI :
if ( e = = fe_button )
1999-04-06 15:34:39 +00:00
sort_orders ( ) ;
break ;
2000-05-05 15:25:49 +00:00
case F_SELECT_ORD :
1999-04-06 15:34:39 +00:00
if ( e = = fe_button )
2000-05-05 15:25:49 +00:00
if ( * get ( F_SEL_ORD_TYPE ) = = ' F ' )
select_orders ( ' F ' , get ( F_OF_DAGRMERC ) , get ( F_OF_AGRMERC ) ) ;
else
select_orders ( ' P ' , get ( F_OP_DAGRMERC ) , get ( F_OP_AGRMERC ) ) ;
1999-04-06 15:34:39 +00:00
break ;
case DLG_SAVEREC :
if ( e = = fe_button & & check_fields ( ) )
{
1999-10-22 10:00:18 +00:00
if ( ! app ( ) . emit_orders ( ) )
2004-05-18 11:17:26 +00:00
message_box ( TR ( " Nessun ordine generato " ) ) ;
1999-04-06 15:34:39 +00:00
}
break ;
1999-10-22 10:00:18 +00:00
case DLG_PRINT :
if ( e = = fe_button )
{
app ( ) . print_orders ( ) ;
return FALSE ;
}
break ;
1999-04-06 15:34:39 +00:00
case DLG_PROFILE :
if ( e = = fe_modify )
{
clear_sheets ( ) ;
enable ( - 1 ) ;
}
break ;
default :
break ;
} ;
return TRUE ;
}
void TMatResMask : : clear_sheets ( )
{
TSheet_field & sa = sfield ( F_ORDINI ) ;
if ( sa . items ( ) > 0 )
{
sa . destroy ( ) ;
sa . force_update ( ) ;
}
}
1999-10-22 10:00:18 +00:00
int TMatResMask : : find_pos ( const TRiga_ordine & r , int & cmp , int level ) const
1999-04-06 15:34:39 +00:00
{
TSheet_field & s = sfield ( F_ORDINI ) ;
TString_array & a = s . rows_array ( ) ;
2006-07-11 13:10:51 +00:00
const bool cmp_orig = get_bool ( F_SINGLE_DOC ) ;
2007-01-03 17:23:36 +00:00
int i ;
cmp = + 1 ; // vacca
for ( i = 0 ; i < a . items ( ) ; i + + )
1999-04-06 15:34:39 +00:00
{
const TRiga_ordine & riga = ( const TRiga_ordine & ) a [ i ] ;
2006-07-11 13:10:51 +00:00
cmp = r . compare ( riga , cmp_orig , level ) ;
1999-10-22 10:00:18 +00:00
if ( cmp = = 0 )
1999-04-06 15:34:39 +00:00
break ;
}
return i ;
}
2000-05-05 15:25:49 +00:00
// Aggiunge le righe d'ordine allo sheet
1999-10-22 10:00:18 +00:00
int TMatResMask : : add_order_line ( long forn , const TMRP_line & line , int bucket )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
const TString & num_forn = get ( F_NUM_FORN ) ;
const TString & num_prod = get ( F_NUM_PROD ) ;
int pos = - 1 ;
1999-10-22 10:00:18 +00:00
TMRP_time deliv_time = line . time ( bucket ) ;
TMRP_time plan_time ;
if ( get_bool ( F_IGN_LDTIME ) )
plan_time = line . time ( bucket ) ;
else
line . lead_time ( bucket , plan_time , TRUE ) ;
plan_time . sub_time ( get_int ( F_XTRA_PLTIME ) ) ;
TDate datadoc = plan_time . date ( ) ;
round_date ( datadoc ) ;
TDate datacons = deliv_time . date ( ) ;
round_date ( datacons ) ;
1999-04-06 15:34:39 +00:00
TSheet_field & s = sfield ( F_ORDINI ) ;
TString_array & a = s . rows_array ( ) ;
2002-12-20 16:15:03 +00:00
real q = line . net_requirement ( bucket ) ; // Fabbisogno netto
2000-05-05 15:25:49 +00:00
TMRP_docrefs * pl_orders = NULL , * sc_orders = NULL ;
if ( get_bool ( F_RESCHEDULING ) )
sc_orders = line . record ( bucket ) . scheduls_refs ( ) ;
pl_orders = line . record ( bucket ) . plans_refs ( ) ;
1999-10-22 10:00:18 +00:00
// le proposte di rescheduling sono da mettere su uno sheet a parte...
2002-12-20 16:15:03 +00:00
int nref = pl_orders ! = NULL ? pl_orders - > items ( ) : 0 ;
real qtaplan ; // Quantit<69> da pianificare
do
{
1999-10-22 10:00:18 +00:00
TRiga_ordine * r = new TRiga_ordine ( datadoc , datacons , forn , line , bucket , ZERO ) ;
2002-12-20 16:15:03 +00:00
// Setta un codice numerazione (provvisorio) in base al tipo di ordine
2006-07-11 13:10:51 +00:00
const char ot = r - > get_char ( F_ORD_TYPE - FIRST_FIELD ) ;
r - > add ( ot = = ' F ' ? num_forn : num_prod , F_DOCCODNUM - FIRST_FIELD ) ;
2002-12-20 16:15:03 +00:00
1999-10-22 10:00:18 +00:00
nref - - ;
if ( nref > = 0 )
2002-12-20 16:15:03 +00:00
{
2006-07-11 13:10:51 +00:00
const TMRP_docref & dr = pl_orders - > get_ref ( nref ) ;
const TString & codnum = dr . codnumdoc ( ) ;
if ( codnum = = num_prod | | codnum = = num_forn )
1999-10-22 10:00:18 +00:00
{
2006-07-11 13:10:51 +00:00
qtaplan = dr . qta_residua ( ) ;
1999-10-22 10:00:18 +00:00
qtaplan . round ( 5 ) ;
q . round ( 5 ) ;
2002-12-20 16:15:03 +00:00
qtaplan = q - qtaplan ; // tengo solo in parte questo ordine ...
2006-07-11 13:10:51 +00:00
r - > add ( dr . annodoc ( ) , F_DOCANNODOC - FIRST_FIELD ) ;
r - > add ( dr . codnumdoc ( ) , F_DOCCODNUM - FIRST_FIELD ) ;
r - > add ( dr . numdoc ( ) , F_DOCNUM - FIRST_FIELD ) ;
r - > add ( dr . numrig ( ) , F_DOCNRIGA - FIRST_FIELD ) ;
2002-12-20 16:15:03 +00:00
r - > add ( qtaplan . is_zero ( ) ? " " : qtaplan . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
2006-07-11 13:10:51 +00:00
r - > add ( dr . datacons ( ) . string ( ) , F_DATACONS - FIRST_FIELD ) ;
r - > add ( dr . datadoc ( ) . string ( ) , F_DATADOC - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
q = ZERO ;
2005-05-16 23:44:23 +00:00
}
else
2000-05-05 15:25:49 +00:00
r - > add ( " " , F_QUANTITA - FIRST_FIELD ) ;
2002-12-20 16:15:03 +00:00
}
else
{
2000-05-05 15:25:49 +00:00
r - > add ( q . is_zero ( ) ? " " : q . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
qtaplan = ZERO ;
}
2006-07-11 13:10:51 +00:00
const TString dadockey ( line . da_rdoc_key ( ) ) ;
r - > add ( dadockey . mid ( 4 , 4 ) , s . cid2index ( F_DAANNO ) ) ;
r - > add ( dadockey . left ( 4 ) , s . cid2index ( F_DACODNUM ) ) ;
r - > add ( dadockey . mid ( 9 , 7 ) , s . cid2index ( F_DANUMDOC ) ) ;
r - > add ( dadockey . mid ( 16 ) , s . cid2index ( F_DANRIGA ) ) ;
2000-10-03 13:45:12 +00:00
if ( ( nref > = 0 & & ( ! qtaplan . is_zero ( ) | | get_bool ( F_ALL_ORDERSCHANGES ) ) ) | | // correggo un vecchio ordine ...
( nref < 0 & & ! q . is_zero ( ) ) | | // ... o ne genero uno nuovo
get_bool ( F_ALL_MRPLINES ) ) // ...o voglio tutte le righe
1999-10-22 10:00:18 +00:00
{
int cmp = - 1 ;
2006-07-11 13:10:51 +00:00
1999-10-22 10:00:18 +00:00
if ( nref > = 0 & & qtaplan < ZERO )
pos = find_pos ( * r , cmp , COMPARE_COMPLETE ) ;
else
pos = find_pos ( * r , cmp , COMPARE_ALL_CODES ) ;
2006-07-11 13:10:51 +00:00
if ( cmp = = 0 ) // RIGA GIA' PRESENTE
1999-10-22 10:00:18 +00:00
{
TRiga_ordine & riga = ( TRiga_ordine & ) a [ pos ] ;
2006-04-13 17:56:02 +00:00
const TString4 codnum = riga . get ( F_DOCCODNUM - FIRST_FIELD ) ;
2002-12-20 16:15:03 +00:00
// if (!(codnum != get(F_NUM_PROD) && codnum != get(F_NUM_FORN)))
2006-07-11 13:10:51 +00:00
if ( codnum = = num_prod | | codnum = = num_forn ) // Guy was here!
2000-05-05 15:25:49 +00:00
riga + = * r ;
1999-10-22 10:00:18 +00:00
delete r ;
2006-07-11 13:10:51 +00:00
const TString & qta2or = riga . get ( F_QUANTITA - FIRST_FIELD ) ;
2000-10-03 13:45:12 +00:00
if ( qta2or [ 0 ] = = ' ' & & !
( ( nref > = 0 & & get_bool ( F_ALL_ORDERSCHANGES ) ) // correzione ..
| | get_bool ( F_ALL_MRPLINES ) ) ) // ... o voglio tutte le righe
{
// riabilita i campi del doc
s . enable_cell ( pos , F_ORD_TYPE - FIRST_FIELD ) ;
s . enable_cell ( pos , F_DATADOC - FIRST_FIELD ) ;
s . enable_cell ( pos , F_DATACONS - FIRST_FIELD ) ;
s . enable_cell ( pos , F_FORNITORE - FIRST_FIELD ) ;
s . enable_cell ( pos , F_MAGAZZINO - FIRST_FIELD ) ;
s . enable_cell ( pos , F_DEPOSITO - FIRST_FIELD ) ;
s . enable_cell ( pos , F_CODIMP - FIRST_FIELD ) ;
s . enable_cell ( pos , F_CODLIN - FIRST_FIELD ) ;
2006-04-13 17:56:02 +00:00
a . destroy ( pos , nref < 0 ) ; // no null rows if not desired
2000-10-03 13:45:12 +00:00
}
1999-10-22 10:00:18 +00:00
}
else
{
2000-05-05 15:25:49 +00:00
// RIGA DA AGGIUNGERE
1999-10-22 10:00:18 +00:00
a . add ( r ) ;
pos = a . items ( ) - 1 ;
2000-05-05 15:25:49 +00:00
}
2006-07-11 13:10:51 +00:00
if ( nref > = 0 )
2000-05-05 15:25:49 +00:00
{
2006-07-11 13:10:51 +00:00
const TMRP_docref & dr = pl_orders - > get_ref ( nref ) ;
const TString & codnum = dr . codnumdoc ( ) ;
TRiga_ordine & riga = ( TRiga_ordine & ) a [ pos ] ;
2000-05-05 15:25:49 +00:00
riga . add ( codnum , F_DOCCODNUM - FIRST_FIELD ) ;
2006-07-11 13:10:51 +00:00
riga . add ( dr . annodoc ( ) , F_DOCANNODOC - FIRST_FIELD ) ;
riga . add ( dr . numdoc ( ) , F_DOCNUM - FIRST_FIELD ) ;
riga . add ( dr . numrig ( ) , F_DOCNRIGA - FIRST_FIELD ) ;
2000-05-05 15:25:49 +00:00
if ( codnum ! = get ( F_NUM_PROD ) & & codnum ! = get ( F_NUM_FORN ) )
riga . add ( " " , F_QUANTITA - FIRST_FIELD ) ;
// disabilita i campi del doc
s . disable_cell ( pos , F_ORD_TYPE - FIRST_FIELD ) ;
s . disable_cell ( pos , F_DATADOC - FIRST_FIELD ) ;
s . disable_cell ( pos , F_DATACONS - FIRST_FIELD ) ;
s . disable_cell ( pos , F_FORNITORE - FIRST_FIELD ) ;
s . disable_cell ( pos , F_MAGAZZINO - FIRST_FIELD ) ;
s . disable_cell ( pos , F_DEPOSITO - FIRST_FIELD ) ;
s . disable_cell ( pos , F_CODIMP - FIRST_FIELD ) ;
s . disable_cell ( pos , F_CODLIN - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
}
}
1999-04-06 15:34:39 +00:00
else
2006-07-11 13:10:51 +00:00
delete r ;
1999-10-22 10:00:18 +00:00
} while ( nref > = 0 /*&& q > ZERO*/ ) ;
2001-06-25 10:41:20 +00:00
if ( line . final_product ( ) )
2001-07-24 13:28:55 +00:00
{
COLOR back = _sel_color . get_back_color ( _nodist_pos ) ;
COLOR fore = _sel_color . get_fore_color ( _nodist_pos ) ;
s . set_back_and_fore_color ( back , fore , pos ) ;
}
1999-04-06 15:34:39 +00:00
return pos ;
}
2006-07-11 13:10:51 +00:00
static int order_compare ( TSheet_field & s , int i1 , int i2 , int sorttype )
1999-04-06 15:34:39 +00:00
{
1999-06-18 15:35:05 +00:00
TMask & m = s . mask ( ) ;
const bool ascending = ! m . get_bool ( F_SORT_ORDER ) ;
2006-07-11 13:10:51 +00:00
const bool cmp_orig = m . get_bool ( F_SINGLE_DOC ) ;
1999-04-06 15:34:39 +00:00
const TRiga_ordine & r1 = ( TRiga_ordine & ) s . row ( i1 ) ;
const TRiga_ordine & r2 = ( TRiga_ordine & ) s . row ( i2 ) ;
2006-07-11 13:10:51 +00:00
return r1 . compare ( r2 , cmp_orig , sorttype , ascending ) ;
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
static int order_compareDTFA ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_DTFA ) ; }
static int order_compareDATF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_DATF ) ; }
static int order_compareATFD ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_ATFD ) ; }
static int order_compareADTF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_ADTF ) ; }
static int order_compareTFAD ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TFAD ) ; }
static int order_compareTFDA ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TFDA ) ; }
static int order_compareTDFA ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TDFA ) ; }
static int order_compareTDAF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TDAF ) ; }
static int order_compareTAFD ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TAFD ) ; }
static int order_compareTADF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TADF ) ; }
1999-04-06 15:34:39 +00:00
2000-10-03 13:45:12 +00:00
static int order_compareCTFA ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_CTFA ) ; }
static int order_compareCATF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_CATF ) ; }
static int order_compareATFC ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_ATFC ) ; }
static int order_compareACTF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_ACTF ) ; }
static int order_compareTFAC ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TFAC ) ; }
static int order_compareTFCA ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TFCA ) ; }
static int order_compareTCFA ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TCFA ) ; }
static int order_compareTCAF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TCAF ) ; }
static int order_compareTAFC ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TAFC ) ; }
static int order_compareTACF ( TSheet_field & s , int i1 , int i2 )
{ return order_compare ( s , i1 , i2 , COMPARE_TACF ) ; }
1999-04-06 15:34:39 +00:00
void TMatResMask : : sort_orders ( )
1999-10-22 10:00:18 +00:00
{
TWait_cursor clessidra ;
2006-07-11 13:10:51 +00:00
TSheet_field & a = sfield ( F_ORDINI ) ;
2000-10-03 13:45:12 +00:00
int choose = - ( get_int ( F_SORT ) + ( get_bool ( F_DATE_SORT_ORDER ) ? 10 : 1 ) ) ;
switch ( choose )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
case COMPARE_ATFD : a . sort ( order_compareATFD ) ; break ;
case COMPARE_ADTF : a . sort ( order_compareADTF ) ; break ;
case COMPARE_DTFA : a . sort ( order_compareDTFA ) ; break ;
case COMPARE_DATF : a . sort ( order_compareDATF ) ; break ;
case COMPARE_TFAD : a . sort ( order_compareTFAD ) ; break ;
case COMPARE_TFDA : a . sort ( order_compareTFDA ) ; break ;
case COMPARE_TAFD : a . sort ( order_compareTAFD ) ; break ;
case COMPARE_TADF : a . sort ( order_compareTADF ) ; break ;
case COMPARE_TDAF : a . sort ( order_compareTDAF ) ; break ;
case COMPARE_TDFA : a . sort ( order_compareTDFA ) ; break ;
2000-10-03 13:45:12 +00:00
case COMPARE_ATFC : a . sort ( order_compareATFC ) ; break ;
case COMPARE_ACTF : a . sort ( order_compareACTF ) ; break ;
case COMPARE_CTFA : a . sort ( order_compareCTFA ) ; break ;
case COMPARE_CATF : a . sort ( order_compareCATF ) ; break ;
case COMPARE_TFAC : a . sort ( order_compareTFAC ) ; break ;
case COMPARE_TFCA : a . sort ( order_compareTFCA ) ; break ;
case COMPARE_TAFC : a . sort ( order_compareTAFC ) ; break ;
case COMPARE_TACF : a . sort ( order_compareTACF ) ; break ;
case COMPARE_TCAF : a . sort ( order_compareTCAF ) ; break ;
case COMPARE_TCFA : a . sort ( order_compareTCFA ) ; break ;
1999-10-22 10:00:18 +00:00
default :
return ;
1999-04-06 15:34:39 +00:00
}
2006-07-11 13:10:51 +00:00
a . force_update ( ) ;
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
bool TMatResMask : : orders_selected ( char type , const char * dacatmer , const char * acatmer )
1999-04-06 15:34:39 +00:00
{
TSheet_field & s = sfield ( F_ORDINI ) ;
const int it = s . items ( ) ;
for ( int r = 0 ; r < it ; r + + )
{
if ( * s . cell ( r , s . cid2index ( F_ORD_TYPE ) ) = = type
& & * s . cell ( r , s . cid2index ( F_SELECTED ) ) = = ' X ' )
1999-10-22 10:00:18 +00:00
if ( * dacatmer < = ' ' | |
cache ( ) . get ( LF_ANAMAG , s . cell ( r , s . cid2index ( F_ARTICOLO ) ) ) . get ( ANAMAG_GRMERC ) . left ( 3 ) > = dacatmer )
if ( * acatmer < = ' ' | |
cache ( ) . get ( LF_ANAMAG , s . cell ( r , s . cid2index ( F_ARTICOLO ) ) ) . get ( ANAMAG_GRMERC ) . left ( 3 ) < = acatmer )
return TRUE ;
1999-04-06 15:34:39 +00:00
}
return FALSE ;
}
1999-10-22 10:00:18 +00:00
void TMatResMask : : select_orders ( char type , const char * dacatmer , const char * acatmer )
1999-04-06 15:34:39 +00:00
{
TSheet_field & s = sfield ( F_ORDINI ) ;
1999-10-22 10:00:18 +00:00
bool on = ! orders_selected ( type , dacatmer , acatmer ) ;
1999-04-06 15:34:39 +00:00
const int it = s . items ( ) ;
for ( int r = 0 ; r < it ; r + + )
{
if ( * s . cell ( r , s . cid2index ( F_ORD_TYPE ) ) = = type )
1999-10-22 10:00:18 +00:00
if ( * dacatmer < = ' ' | |
cache ( ) . get ( LF_ANAMAG , s . cell ( r , s . cid2index ( F_ARTICOLO ) ) ) . get ( ANAMAG_GRMERC ) . left ( 3 ) > = dacatmer )
if ( * acatmer < = ' ' | |
cache ( ) . get ( LF_ANAMAG , s . cell ( r , s . cid2index ( F_ARTICOLO ) ) ) . get ( ANAMAG_GRMERC ) . left ( 3 ) < = acatmer )
{
s . row ( r ) . add ( on ? " X " : " " , s . cid2index ( F_SELECTED ) ) ;
s . force_update ( r ) ;
}
1999-04-06 15:34:39 +00:00
}
2004-05-18 11:17:26 +00:00
TString msg = format ( FR ( " Ordini %s %s " ) , type = = ' F ' ? TR ( " fornitore " ) : TR ( " di produzione " ) , on ? TR ( " selezionati " ) : TR ( " de-selezionati " ) ) ;
2005-10-05 17:36:22 +00:00
xvtil_statbar_set ( msg ) ;
1999-04-06 15:34:39 +00:00
}
2008-06-11 10:58:17 +00:00
static bool handle_interval ( TMask_field & fld , KEY k )
{
if ( fld . to_check ( k , true ) )
{
TMatResMask & m = ( ( TMatResMask & ) fld . mask ( ) ) ;
const TDate & from = m . get_date ( F_DADATA ) ;
const TDate & to = m . get_date ( F_ADATA ) ;
1999-04-06 15:34:39 +00:00
2008-06-11 10:58:17 +00:00
m . calendar ( ) . set_highlight_interval ( from , to ) ;
}
return true ;
}
1999-04-06 15:34:39 +00:00
2002-12-18 11:58:58 +00:00
TMatResMask : : TMatResMask ( ) : TCalendar_mask ( " mr2100a " ) , _sel_color ( sfield ( F_ORDINI ) )
1999-04-06 15:34:39 +00:00
{
_condv = NULL ;
TSheet_field & sf = sfield ( F_ORDINI ) ;
2002-12-20 16:15:03 +00:00
1999-10-22 10:00:18 +00:00
livelli_giacenza ( ) . set_sheet_columns ( sf , F_LIV1 ) ;
1999-04-06 15:34:39 +00:00
TConfig ini ( CONFIG_DITTA , " mg " ) ;
if ( ! ini . get_bool ( " GESDEPOSITI " , " mg " ) )
{
sf . delete_column ( F_DEPOSITO ) ;
sf . sheet_mask ( ) . hide ( F_DEPOSITO ) ;
}
if ( ! ini . get_bool ( " GESTIMPIANTI " , " mr " ) )
{
sf . delete_column ( F_CODIMP ) ; // Elimina colonna impianto
sf . sheet_mask ( ) . hide ( F_CODIMP ) ;
sf . sheet_mask ( ) . hide ( F_DESCIMP ) ;
disable ( F_NOIMP ) ; // Forza l'ignoramento degli impianti
set ( F_NOIMP , " X " ) ;
2001-07-24 13:28:55 +00:00
}
2004-05-18 11:17:26 +00:00
_nodist_pos = _sel_color . add_color_def ( " NODIST " , TR ( " Art.pianificati senza distinta " ) , COLOR_YELLOW , COLOR_BLACK ) ;
2008-06-11 10:58:17 +00:00
set_handler ( F_DADATA , handle_interval ) ;
set_handler ( F_ADATA , handle_interval ) ;
TCalendar_field & cf = ( TCalendar_field & ) field ( F_CALENDAR ) ;
cf . set_immediate_write ( ) ;
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
///////////////////////////////////////////////////////////
// TRisalita_mask :
///////////////////////////////////////////////////////////
2006-07-11 13:10:51 +00:00
TRisalita_mask : : TRisalita_mask ( TMRP_line * line , const TDate & fromdate , const TDate & todate ,
bool isbuck0 , int extraleadtime )
1999-10-22 10:00:18 +00:00
: TAutomask ( " mr2100b.msk " ) , _line ( line )
{
TSheet_field & sf = sfield ( F_ORDINI ) ;
sf . disable ( ) ;
livelli_giacenza ( ) . set_sheet_columns ( sf , F_LIV1 ) ;
livelli_giacenza ( ) . set_mask_fields ( * this , F_LIV1 ) ;
TConfig ini ( CONFIG_DITTA , " mg " ) ;
if ( ! ini . get_bool ( " GESDEPOSITI " , " mg " ) )
{
sf . delete_column ( F_DEPOSITO ) ;
sf . sheet_mask ( ) . hide ( F_DEPOSITO ) ;
}
if ( ! ini . get_bool ( " GESTIMPIANTI " , " mr " ) )
{
sf . delete_column ( F_CODIMP ) ; // Elimina colonna impianto
sf . sheet_mask ( ) . hide ( F_CODIMP ) ;
sf . sheet_mask ( ) . hide ( F_DESCIMP ) ;
}
TToken_string cod = line - > articolo ( ) ;
set ( F_ARTICOLO , cod ) ;
set ( F_DESCART , line - > description ( ) ) ;
cod . add ( " 1 " ) ;
set ( F_UM , cache ( ) . get ( LF_UMART , cod ) . get ( " UM " ) ) ;
for ( int l = livelli_giacenza ( ) . last_level ( ) ; l > = 1 ; l - - )
set ( F_LIV1 + l - 1 , line - > livgiac ( l ) ) ;
bool has_internal_refs = FALSE ;
real lordo , netto , plan , sched ;
for ( int b = line - > last_bucket ( ) ; b > = 0 ; b - - )
{
2000-05-05 15:25:49 +00:00
// TMRP_time dtime = line->record(b).time();
// if (extraleadtime && line->sons() == 0)
// dtime.sub_time(extraleadtime);
// const TDate &d = dtime.date();
2000-10-03 13:45:12 +00:00
const TDate & d = line - > record ( b ) . time ( ) . date ( ) ;
if ( isbuck0 | | d > = fromdate )
1999-10-22 10:00:18 +00:00
{
2000-05-05 15:25:49 +00:00
set ( F_FABB_DADATA , isbuck0 ? " " : fromdate ) ;
1999-10-22 10:00:18 +00:00
set ( F_FABB_ADATA , todate ) ;
set ( F_FABB_GIAC , line - > record ( b ) . on_hand ( ) . string ( ) ) ;
if ( d < = todate )
{
lordo + = line - > gross_requirement ( b ) ;
netto + = line - > net_requirement ( b ) ;
plan + = line - > planned_orders ( b ) ;
sched + = line - > sched_receipts ( b ) ;
TMRP_internalrefs * irefs = line - > record ( b ) . internal_refs ( ) ;
if ( irefs )
{
int ir = 0 ;
while ( ir < irefs - > items ( ) )
{
TMRP_internalref & iref = irefs - > get_ref ( ir ) ;
add_internal_ref ( iref ) ;
ir + + ;
}
has_internal_refs = TRUE ;
} else {
add_gross_ref ( * line , b ) ;
}
}
}
}
if ( ! has_internal_refs )
for ( int c = F_ARTICOLO ; c < F_DOCANNODOC ; c + + )
sf . delete_column ( c ) ;
add_total_rows ( ) ;
set ( F_FABB_LORDO , lordo . string ( ) ) ;
set ( F_FABB_PIAN , plan . string ( ) ) ;
set ( F_FABB_SCHED , sched . string ( ) ) ;
netto - = plan ;
set ( F_TOPLAN , netto . string ( ) ) ;
netto + = plan + sched ;
set ( F_FABB_NETTO , netto . string ( ) ) ;
}
bool TRisalita_mask : : add_total_rows ( )
{
TSheet_field & sf = sfield ( F_ORDINI ) ;
if ( sf . items ( ) = = 0 )
return FALSE ;
sf . sort ( compare_rows ) ;
TString codice ( get ( F_ARTICOLO ) ) , codpadre , um ;
const TCodice_um um_nulla ;
TQuantita totale ( codice , um_nulla , ZERO ) ;
TQuantita parziale ( totale ) , qta , lordopadre ;
real val ;
int padri ( 0 ) , riga ( 0 ) ;
TToken_string * row ;
TString_array & ra = sf . rows_array ( ) ;
while ( row = ( TToken_string * ) ra . objptr ( riga + + ) )
{
if ( codpadre ! = row - > get ( sf . cid2index ( F_ARTICOLO ) ) )
{
if ( ! codpadre . blank ( ) )
{
add_total_row ( riga + + , parziale . um ( ) , parziale . val ( ) , lordopadre . um ( ) , lordopadre . val ( ) ) ;
parziale . set_val ( ZERO ) ;
lordopadre . set_articolo ( codpadre , um_nulla ) ;
lordopadre . set_val ( ZERO ) ;
padri + + ;
}
codpadre = row - > get ( sf . cid2index ( F_ARTICOLO ) ) ;
}
// fabbisogno articolo
row - > get ( sf . cid2index ( F_FABBISOGNO ) , val ) ;
row - > get ( sf . cid2index ( F_UMFABB ) , um ) ;
qta . set ( codice , um , val ) ;
parziale + = qta ;
totale + = qta ;
// qta padre
row - > get ( sf . cid2index ( F_QUANTITA ) , val ) ;
row - > get ( sf . cid2index ( F_UM ) , um ) ;
qta . set ( codpadre . blank ( ) ? codice : codpadre , um , val ) ;
lordopadre + = qta ;
}
add_total_row ( riga + + , parziale . um ( ) , parziale . val ( ) , lordopadre . um ( ) , lordopadre . val ( ) ) ;
if ( padri > 0 )
add_total_row ( riga , totale . um ( ) , totale . val ( ) , " " , ZERO ) ;
sf . force_update ( ) ;
2002-12-18 11:58:58 +00:00
return padri ! = 0 ;
1999-10-22 10:00:18 +00:00
}
2006-07-11 13:10:51 +00:00
int TRisalita_mask : : compare_rows ( TSheet_field & sf , int r1 , int r2 )
1999-10-22 10:00:18 +00:00
{
2006-07-11 13:10:51 +00:00
const TToken_string & s1 = sf . row ( r1 ) ;
const TToken_string & s2 = sf . row ( r2 ) ;
TString80 ss1 , ss2 ;
1999-10-22 10:00:18 +00:00
s1 . get ( sf . cid2index ( F_ARTICOLO ) , ss1 ) ;
s2 . get ( sf . cid2index ( F_ARTICOLO ) , ss2 ) ;
int d = ss1 . compare ( ss2 ) ;
if ( d = = 0 )
{
2006-07-11 13:10:51 +00:00
TDate d1 , d2 ;
1999-10-22 10:00:18 +00:00
s1 . get ( sf . cid2index ( F_DATACONS ) , ss1 ) ;
s2 . get ( sf . cid2index ( F_DATACONS ) , ss2 ) ;
d1 = ss1 ;
d2 = ss2 ;
d = int ( d1 - d2 ) ;
if ( d = = 0 )
{
s1 . get ( sf . cid2index ( F_FABBISOGNO ) , ss1 ) ;
s2 . get ( sf . cid2index ( F_FABBISOGNO ) , ss2 ) ;
real r1 ( ss1 ) , r2 ( ss2 ) ;
r1 - = r2 ;
d = r1 . sign ( ) ;
}
}
return d ;
}
2006-07-11 13:10:51 +00:00
bool TRisalita_mask : : add_total_row ( int pos , const char * um , const real & lordo , const char * umpadre , const real & lordopadre )
1999-10-22 10:00:18 +00:00
{
TSheet_field & sf = sfield ( F_ORDINI ) ;
sf . insert ( - - pos ) ;
TToken_string & row = sf . row ( pos ) ;
row . add ( um , sf . cid2index ( F_UMFABB ) ) ;
row . add ( lordo . string ( ) , sf . cid2index ( F_FABBISOGNO ) ) ;
row . add ( umpadre , sf . cid2index ( F_UM ) ) ;
row . add ( lordopadre . string ( ) , sf . cid2index ( F_QUANTITA ) ) ;
sf . disable_row ( pos ) ;
2006-07-11 13:10:51 +00:00
return true ;
1999-10-22 10:00:18 +00:00
}
bool TRisalita_mask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
switch ( o . dlg ( ) )
{
2006-07-11 13:10:51 +00:00
case F_RISALITA :
1999-10-22 10:00:18 +00:00
if ( e = = fe_button )
app ( ) . risalita ( * this ) ;
2006-07-11 13:10:51 +00:00
break ;
default :
1999-10-22 10:00:18 +00:00
break ;
}
2006-07-11 13:10:51 +00:00
return true ;
1999-10-22 10:00:18 +00:00
}
int TRisalita_mask : : add_internal_ref ( const TMRP_internalref & iref )
{
const TMRP_line & line = * iref . line ( ) ;
2005-05-16 23:44:23 +00:00
int bucket = iref . bucket ( ) ;
1999-10-22 10:00:18 +00:00
const TMRP_time & deliv_time = line . time ( bucket ) ;
TMRP_time doc_time ;
line . lead_time ( bucket , doc_time , TRUE ) ;
TSheet_field & s = sfield ( F_ORDINI ) ;
TString_array & a = s . rows_array ( ) ;
TToken_string dockey ;
TMRP_docrefs * gr_refs = line . record ( bucket ) . requirements_refs ( ) ;
int grref = gr_refs ? gr_refs - > items ( ) : 0 ;
TMRP_docrefs * pl_refs = line . record ( bucket ) . plans_refs ( ) ;
int plref = pl_refs ? pl_refs - > items ( ) : 0 ;
TMRP_docrefs * sr_refs = line . record ( bucket ) . scheduls_refs ( ) ;
int srref = sr_refs ? sr_refs - > items ( ) : 0 ;
real totreq = line . net_requirement ( bucket ) ;
totreq + = line . sched_receipts ( bucket ) ;
real qtaplan ( totreq ) ;
real qtareq ( totreq ) ;
do {
TCodice_um um ;
TToken_string r ;
real q = iref . qta ( ) ;
TMRP_docref * docref = NULL ;
if ( grref > 0 )
docref = gr_refs - > get_ref_ptr ( - - grref ) ;
else if ( srref > 0 )
docref = sr_refs - > get_ref_ptr ( - - srref ) ;
else if ( plref > 0 )
docref = pl_refs - > get_ref_ptr ( - - plref ) ;
if ( docref )
{
dockey . add ( " D " , 0 ) ;
dockey . add ( docref - > annodoc ( ) , 1 ) ;
dockey . add ( docref - > codnumdoc ( ) , 2 ) ;
dockey . add ( docref - > numdoc ( ) , 3 ) ;
//const TString & codnum = docref->codnumdoc();
qtaplan = docref - > qta_residua ( ) ;
qtaplan . round ( 5 ) ;
TQuantita qta ( line . articolo ( ) , docref - > um ( ) , docref - > qta_residua ( ) ) ;
qta . convert2umbase ( ) ;
qtareq = qtareq - qta . val ( ) ;
qtareq . round ( 5 ) ;
2000-10-03 13:45:12 +00:00
// qtareq = qtareq - qtaplan;
1999-10-22 10:00:18 +00:00
r . add ( cache ( ) . get ( LF_DOC , dockey ) . get ( DOC_DATADOC ) , F_DATADOC - FIRST_FIELD ) ; // data del documento di rif.
r . add ( docref - > annodoc ( ) , F_DOCANNODOC - FIRST_FIELD ) ;
r . add ( docref - > codnumdoc ( ) , F_DOCCODNUM - FIRST_FIELD ) ;
r . add ( docref - > numdoc ( ) , F_DOCNUM - FIRST_FIELD ) ;
r . add ( docref - > numrig ( ) , F_DOCNRIGA - FIRST_FIELD ) ;
r . add ( qtaplan . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
um = docref - > um ( ) ;
2005-05-16 23:44:23 +00:00
const TRectype & rdoc = docref - > get_rdoc ( ) ;
r . add ( rdoc . get ( RDOC_DAANNO ) , F_DAANNO - FIRST_FIELD ) ;
r . add ( rdoc . get ( RDOC_DACODNUM ) , F_DACODNUM - FIRST_FIELD ) ;
r . add ( rdoc . get ( RDOC_DANDOC ) , F_DANUMDOC - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
}
else
{
qtaplan = qtareq ;
r . add ( doc_time . date ( ) . string ( ) , F_DATADOC - FIRST_FIELD ) ;
}
TQuantita qta ( line . articolo ( ) , um , qtaplan ) ;
r . add ( get ( F_UM ) , F_UMFABB - FIRST_FIELD ) ;
r . add ( deliv_time . date ( ) . string ( ) , F_DATACONS - FIRST_FIELD ) ;
r . add ( " " , F_FORNITORE - FIRST_FIELD ) ;
r . add ( line . articolo ( ) , F_ARTICOLO - FIRST_FIELD ) ;
const TString & liv = line . livgiac ( ) ;
for ( int l = livelli_giacenza ( ) . last_level ( ) ; l > = 1 ; l - - )
r . add ( line . livgiac ( l ) , F_LIV1 + l - 1 - FIRST_FIELD ) ;
r . add ( line . codmag ( ) , F_MAGAZZINO - FIRST_FIELD ) ;
r . add ( line . coddep ( ) , F_DEPOSITO - FIRST_FIELD ) ;
r . add ( line . codimp ( ) , F_CODIMP - FIRST_FIELD ) ;
r . add ( line . codlin ( ) , F_CODLIN - FIRST_FIELD ) ;
r . add ( " " , F_PREZZO - FIRST_FIELD ) ;
r . add ( line . description ( ) , F_DESCART - FIRST_FIELD ) ;
r . add ( qta . val ( ) . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
r . add ( qta . um ( ) , F_UM - FIRST_FIELD ) ;
// aggiunge il fabbisogno
qta . convert2umbase ( ) ;
2000-10-03 13:45:12 +00:00
q = iref . qta ( ) * qta . val ( ) / totreq ;
1999-10-22 10:00:18 +00:00
r . add ( q . string ( ) , F_FABBISOGNO - FIRST_FIELD ) ;
a . add ( r ) ;
} while ( ( grref > 0 | | srref > 0 | | plref > 0 ) & & qtareq > ZERO ) ;
return 0 ;
}
int TRisalita_mask : : add_gross_ref ( const TMRP_line & line , int bucket )
{
TSheet_field & s = sfield ( F_ORDINI ) ;
TString_array & a = s . rows_array ( ) ;
TToken_string dockey ;
real totreq , qtaplan , qtareq ;
TMRP_time deliv_time = line . time ( bucket ) ;
TMRP_time doc_time ;
line . lead_time ( bucket , doc_time , TRUE ) ;
TToken_string r ;
//const TString & codnum = docref->codnumdoc();
TMRP_docref * docref = NULL ;
TMRP_docrefs * gr_refs = line . record ( bucket ) . requirements_refs ( ) ;
int grref = gr_refs ? gr_refs - > items ( ) : 0 ;
while ( grref )
{
docref = gr_refs - > get_ref_ptr ( - - grref ) ;
qtaplan = docref - > qta_residua ( ) ;
qtaplan . round ( 5 ) ;
dockey . add ( " D " , 0 ) ;
dockey . add ( docref - > annodoc ( ) , 1 ) ;
dockey . add ( docref - > codnumdoc ( ) , 2 ) ;
dockey . add ( docref - > numdoc ( ) , 3 ) ;
r . add ( cache ( ) . get ( LF_DOC , dockey ) . get ( DOC_DATADOC ) , F_DATADOC - FIRST_FIELD ) ; // data del documento di rif.
r . add ( docref - > annodoc ( ) , F_DOCANNODOC - FIRST_FIELD ) ;
r . add ( docref - > codnumdoc ( ) , F_DOCCODNUM - FIRST_FIELD ) ;
r . add ( docref - > numdoc ( ) , F_DOCNUM - FIRST_FIELD ) ;
r . add ( docref - > numrig ( ) , F_DOCNRIGA - FIRST_FIELD ) ;
r . add ( deliv_time . date ( ) . string ( ) , F_DATACONS - FIRST_FIELD ) ;
r . add ( " " , F_FORNITORE - FIRST_FIELD ) ;
const TCodice_um um_nulla ;
const TQuantita qta ( line . articolo ( ) , docref - > um ( ) , qtaplan ) ;
r . add ( qta . val ( ) . string ( ) , F_QUANTITA - FIRST_FIELD ) ;
r . add ( qta . um ( ) , F_UM - FIRST_FIELD ) ;
r . add ( qtaplan . string ( ) , F_FABBISOGNO - FIRST_FIELD ) ;
r . add ( qta . um ( ) , F_UMFABB - FIRST_FIELD ) ;
a . add ( r ) ;
}
return 0 ;
}
1999-04-06 15:34:39 +00:00
///////////////////////////////////////////////////////////
// TMatResPlanning
///////////////////////////////////////////////////////////
2009-02-14 17:13:09 +00:00
bool TMatResPlanning : : test_codnum ( const TString & codnum , const TString_array & a ) const
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
TString4 tmp ;
2009-02-14 17:13:09 +00:00
FOR_EACH_ARRAY_ROW ( a , i , row )
1999-06-18 15:35:05 +00:00
{
2009-02-14 17:13:09 +00:00
row - > get ( 0 , tmp ) ;
2006-07-11 13:10:51 +00:00
if ( tmp = = codnum )
return true ;
1999-06-18 15:35:05 +00:00
}
2006-07-11 13:10:51 +00:00
return false ;
2009-02-14 17:13:09 +00:00
}
bool TMatResPlanning : : test_codnum ( const TCodice_numerazione & num , const TString_array & a ) const
{
const TString & codnum = num . codice ( ) ;
return test_codnum ( codnum , a ) ;
1999-04-06 15:34:39 +00:00
}
2006-04-13 17:56:02 +00:00
bool TMatResPlanning : : has_confirmed_status ( const TRectype & doc , const TToken_string & riga ) const
1999-06-18 15:35:05 +00:00
{
2009-02-14 17:13:09 +00:00
char statodoc = doc . get_char ( DOC_STATO ) ;
char state_def ; riga . get ( F_STATODEF - FIRST_FIELD , state_def ) ;
return statodoc > = state_def ;
1999-06-18 15:35:05 +00:00
}
2006-07-11 13:10:51 +00:00
int TMatResPlanning : : test_status ( const TRectype & doc , const TString_array & a ) const
1999-04-06 15:34:39 +00:00
{
2006-04-13 17:56:02 +00:00
const TString4 tipodoc = doc . get ( DOC_TIPODOC ) ;
1999-06-18 15:35:05 +00:00
const char statodoc = doc . get_char ( DOC_STATO ) ;
for ( int i = a . items ( ) - 1 ; i > = 0 ; i - - )
1999-04-06 15:34:39 +00:00
{
2006-04-13 17:56:02 +00:00
TToken_string & riga = ( TToken_string & ) a . row ( i ) ;
1999-04-06 15:34:39 +00:00
const char * t = riga . get ( 0 ) ;
if ( tipodoc = = t )
{
1999-06-18 15:35:05 +00:00
const char state_fr = riga . get_char ( F_DASTATO - FIRST_FIELD ) ;
const char state_to = riga . get_char ( F_ASTATO - FIRST_FIELD ) ;
if ( statodoc > = state_fr & & statodoc < = state_to )
return i ;
1999-04-06 15:34:39 +00:00
}
}
1999-06-18 15:35:05 +00:00
return - 1 ;
1999-04-06 15:34:39 +00:00
}
/////////// finished: 100%
/////////// tested : 100%
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : load_gross_requirements ( )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
const TMatResMask & m = * _mask ;
1999-04-06 15:34:39 +00:00
TDate date_fr = m . get ( F_DADATA ) ;
const int bucket_fr = m . round_date ( date_fr , FALSE ) ;
TDate date_to = m . get ( F_ADATA ) ;
const int bucket_to = m . round_date ( date_to , TRUE ) ;
2006-07-11 13:10:51 +00:00
const int year_fr = date_fr . year ( ) - ( m . get_bool ( F_DOC_YEAR_PREC ) ? 1 : 0 ) ;
1999-04-06 15:34:39 +00:00
const int year_to = date_to . year ( ) ;
2002-12-20 16:15:03 +00:00
const bool master = m . get ( F_ORC_MASTER ) [ 0 ] = = ' M ' ; // Master Plan o Ordine Cliente
1999-04-06 15:34:39 +00:00
// azzera l'array _requirements
const bool nomag = m . get_bool ( F_NOMAG ) ;
1999-10-22 10:00:18 +00:00
const bool nodep = m . get_bool ( F_NODEP ) ;
1999-04-06 15:34:39 +00:00
const bool noimp = m . get_bool ( F_NOIMP ) ;
const bool nolin = m . get_bool ( F_NOLIN ) ;
2006-07-11 13:10:51 +00:00
const bool nokey = ! m . get_bool ( F_SINGLE_DOC ) ;
_articles . ignore ( nomag , nodep , noimp , nolin , nokey ) ;
1999-04-06 15:34:39 +00:00
_articles . destroy ( ) ;
TTable num ( " %NUM " ) ;
TCodice_numerazione cod ;
TRelation rel ( LF_DOC ) ;
TCursor cur ( & rel ) ;
const TRectype & curr_doc = cur . curr ( ) ;
TRectype filter_fr ( curr_doc ) , filter_to ( curr_doc ) ;
TString_array & n = m . sfield ( F_NUM_ORC ) . rows_array ( ) ;
TString_array & a = m . sfield ( F_TIPI_ORC ) . rows_array ( ) ;
// Scandisce tutte le numerazioni considerando solo quelle
// contenenti i tipi documento specificati nella maschera
2005-05-16 23:44:23 +00:00
// Inizializza la cache delle lavorazioni
_artinfo . init ( m . get_bool ( F_KEEP_IMP ) ) ;
2006-07-11 13:10:51 +00:00
for ( int err = cod . first ( num ) ; err = = NOERR ; err = cod . next ( num ) ) if ( test_codnum ( cod , n ) )
{
// Filtra il cursore in modo da limitarlo alla numerazione
// corrente ed agli anni specificati dalle due date limite
cur . freeze ( false ) ;
filter_fr . put ( DOC_PROVV , " D " ) ;
filter_fr . put ( DOC_ANNO , year_fr ) ;
filter_fr . put ( DOC_CODNUM , cod . codice ( ) ) ;
filter_to . put ( DOC_PROVV , " D " ) ;
filter_to . put ( DOC_ANNO , year_to ) ;
filter_to . put ( DOC_CODNUM , cod . codice ( ) ) ;
cur . setregion ( filter_fr , filter_to ) ;
TString16 cfilter ;
cfilter < < DOC_CODNUM < < " == \" " < < cod . codice ( ) < < ' " ' ;
cur . setfilter ( cfilter ) ;
const long items = cur . items ( ) ;
cur . freeze ( true ) ;
// Scandisce i documenti inevasi e considera solo
// quelli con uno stato nel range corretto
TString msg ; msg < < TR ( " Caricamento fabbisogni lordi " ) < < " ... ( " < < cod . codice ( ) < < ' ) ' ;
TProgind pi ( items , msg , true , true ) ;
for ( cur = 0 ; cur . pos ( ) < items ; + + cur )
{
if ( ! pi . addstatus ( 1 ) )
break ;
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
const bool evaso = curr_doc . get_bool ( DOC_DOCEVASO ) ;
if ( evaso )
continue ;
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
TDate doc_cons = curr_doc . get ( DOC_DATACONS ) ;
if ( ! doc_cons . ok ( ) )
doc_cons = curr_doc . get ( DOC_DATADOC ) ;
if ( test_status ( curr_doc , a ) > = 0 )
{
// Scandisce le righe articolo e memorizza le quantita' richieste
const TDocumento doc ( curr_doc ) ;
for ( int r = doc . physical_rows ( ) ; r > 0 ; r - - )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
// Seleziona le righe articolo non ancora evase
const TRiga_documento & riga = doc [ r ] ;
if ( ! riga . is_articolo ( ) )
continue ;
TDate datacons = riga . get ( RDOC_DATACONS ) ;
if ( ! datacons . ok ( ) ) datacons = doc_cons ;
// Data consegna troppo avanti
if ( datacons > date_to )
continue ;
const real qta = riga . qtaresidua ( ) ;
if ( qta > ZERO )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
const TCodice_articolo art = riga . get ( RDOC_CODARTMAG ) ;
const TString16 liv = riga . get ( RDOC_LIVELLO ) ;
TString8 mag = nomag ? EMPTY_STRING : riga . get ( RDOC_CODMAG ) . left ( nodep ? 3 : 5 ) ;
TString8 imp = noimp ? EMPTY_STRING : riga . get ( RDOC_IMPIANTO ) ;
TString8 lin = nolin ? EMPTY_STRING : riga . get ( RDOC_LINEA ) ;
const TCodice_um um = riga . get ( RDOC_UMQTA ) ;
2005-06-01 11:20:06 +00:00
2006-07-11 13:10:51 +00:00
// GUY was Here, but it's Koki fault!
const long codcli = is_production_article ( art ) ? doc . get_long ( DOC_CODCF ) : 0 ;
TString80 rdoc_key = riga . build_key ( ) ;
rdoc_key . format ( " %-4s%4dD%7ld%4d " ,
( const char * ) riga . get ( RDOC_CODNUM ) , riga . get_int ( RDOC_ANNO ) ,
riga . get_long ( RDOC_NDOC ) , riga . get_int ( RDOC_IDRIGA ) ) ;
TPrice prz ( riga . prezzo ( TRUE , TRUE ) ) ;
TQuantita q ( art , um , qta ) ;
q . convert2umbase ( ) ;
q . currency2umbase ( prz ) ;
if ( lin . empty ( ) )
_artinfo . art2magimpline ( art , mag , imp , lin ) ;
TMRP_line * line = _articles . find ( art , liv , mag , EMPTY_STRING , imp , lin , codcli , rdoc_key ) ;
if ( line = = NULL )
{
// nuova linea
line = _articles . find ( art , liv , mag , EMPTY_STRING , imp , lin , codcli , rdoc_key , true ) ;
line - > set_description ( riga . get ( RDOC_DESCR ) ) ;
line - > set_final_product ( ) ;
}
const int anno = doc . get_int ( DOC_ANNO ) ;
const TString4 codnum = doc . get ( DOC_CODNUM ) ;
const long ndoc = doc . get_long ( DOC_NDOC ) ;
const int numriga = riga . get_int ( RDOC_NRIGA ) ;
TMRP_docref * docref = new TMRP_docref ( anno , codnum , ndoc ,
numriga , um , qta , prz . get_num ( ) ) ;
TMRP_time t ( datacons , 0 , imp , lin ) ;
if ( m . get_int ( F_LDTIME_MODE ) ! = 0 )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
t . add_time ( 0 , - 1 ) ; // Toglie un'ora: sposta datacons a fine turno
t . add_time ( 0 , + 1 ) ; // Riaggiunge un'ora nel giorno stesso
1999-04-06 15:34:39 +00:00
}
2006-07-11 13:10:51 +00:00
line - > add_gross_req ( t , q . val ( ) , docref ) ;
if ( master )
line - > add_net_req ( t , q . val ( ) ) ;
1999-04-06 15:34:39 +00:00
}
}
}
}
}
return _articles . items ( ) > 0L ;
}
/////////// finished: 100%
/////////// tested : 100%
2008-06-11 10:58:17 +00:00
static bool cyclic ( TTree & tree , void * jolly , word flags )
{
TDistinta_tree & distinta = ( TDistinta_tree & ) tree ;
return distinta . is_cyclic ( ) ;
}
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : explode_articles ( )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
const TMatResMask & m = * _mask ;
1999-04-06 15:34:39 +00:00
TDistinta_tree distinta ; // albero distinta
TArray boom ; // array per i figli
2005-05-16 23:44:23 +00:00
int level = 0 ;
int maxlevel = m . get_int ( F_MAXLEVEL ) ;
2001-06-25 10:41:20 +00:00
bool finiti = TRUE ;
1999-04-06 15:34:39 +00:00
TProgind * pi = NULL ;
// Inizializza la cache delle lavorazioni
2005-05-16 23:44:23 +00:00
// _artinfo.init(m.get_bool(F_KEEP_IMP)); ??
1999-04-06 15:34:39 +00:00
// Scandisce gli articoli inseriti dal gross requirements ed
// accoda tutti gli articoli risultanti dalla loro esplosione
for ( long a = 0 ; a < _articles . items ( ) ; a + + )
{
if ( pi & & pi - > isfinished ( ) )
{
2006-07-11 13:10:51 +00:00
delete pi ; pi = NULL ;
2001-06-25 10:41:20 +00:00
finiti = FALSE ;
1999-04-06 15:34:39 +00:00
}
if ( pi = = NULL )
{
2005-05-16 23:44:23 +00:00
if ( maxlevel > 0 & & level > = maxlevel )
return _articles . items ( ) > 0 ;
1999-04-06 15:34:39 +00:00
TString80 msg ;
2005-05-16 23:44:23 +00:00
msg . format ( FR ( " Esplosione articoli (livello %d) " ) , + + level ) ;
1999-04-06 15:34:39 +00:00
pi = new TProgind ( _articles . items ( ) - a , msg , TRUE , TRUE ) ;
}
2006-07-11 13:10:51 +00:00
if ( ! pi - > addstatus ( 1 ) )
{
delete pi ; pi = NULL ;
1999-04-06 15:34:39 +00:00
return FALSE ;
2006-07-11 13:10:51 +00:00
}
1999-04-06 15:34:39 +00:00
TMRP_line & line = _articles [ a ] ;
2005-02-17 18:13:12 +00:00
// Se la linea dell'articolo principale e' vuota (non c'era sull'ordine) me la invento.
if ( line . codlin ( ) . empty ( ) )
{
TString8 mag = line . codmagdep ( ) , imp = line . codimp ( ) , lin = line . codlin ( ) ;
_artinfo . art2magimpline ( line . articolo ( ) , mag , imp , lin ) ;
2006-04-13 17:56:02 +00:00
if ( lin . full ( ) )
2005-02-17 18:13:12 +00:00
line . set_imp_lin ( imp , lin ) ;
}
2000-05-05 15:25:49 +00:00
distinta . set_global ( " _DISTINTA " , line . articolo ( ) ) ;
distinta . set_global ( " _MAGDEP " , line . codmagdep ( ) ) ;
distinta . set_global ( " _IMPIANTO " , line . codimp ( ) ) ;
distinta . set_global ( " _LINEA " , line . codlin ( ) ) ;
1999-10-22 10:00:18 +00:00
if ( distinta . set_root ( line . articolo ( ) , " " , 1.0 , line . livgiac ( ) ) )
1999-04-06 15:34:39 +00:00
{
2001-06-25 10:41:20 +00:00
line . set_final_product ( FALSE ) ;
2008-06-11 10:58:17 +00:00
distinta . goto_root ( ) ;
if ( distinta . scan_depth_first ( cyclic , NULL ) )
{
TToken_string & rdoc = ( TToken_string & ) line . da_rdoc_key ( ) ;
error_box ( " Ordine %s %d/%ld riga n. %d - Distinta %s ciclica " , ( const char * ) rdoc . left ( 4 ) , atoi ( rdoc . mid ( 4 , 4 ) ) , atoi ( rdoc . mid ( 9 , 7 ) ) , atoi ( rdoc . mid ( 16 ) ) , ( const char * ) line . articolo ( ) ) ;
continue ;
}
distinta . explode ( boom , FALSE , RAGGR_EXP_UMBASE , 1 , " AV " ) ;
1999-04-06 15:34:39 +00:00
for ( int i = 0 ; i < boom . items ( ) ; i + + )
{
const TRiga_esplosione & riga = ( const TRiga_esplosione & ) boom [ i ] ;
const TCodice_articolo & art = riga . articolo ( ) ;
const TRectype & articolo = cache ( ) . get ( LF_ANAMAG , art ) ;
2005-03-17 18:21:37 +00:00
bool add = true ;
2006-07-11 13:10:51 +00:00
if ( articolo . get ( ANAMAG_CODART ) . full ( ) )
1999-04-06 15:34:39 +00:00
{
const char reorder_type = articolo . get_char ( ANAMAG_RIORDINO ) ;
if ( reorder_type ! = ' F ' & & reorder_type ! = ' ' & & reorder_type ! = ' \0 ' ) // e' a riordino
2005-03-17 18:21:37 +00:00
add = false ;
1999-04-06 15:34:39 +00:00
}
if ( add )
{
// articolo gestito dall'MRP
1999-10-22 10:00:18 +00:00
TString8 mag = line . codmagdep ( ) ;
TString8 imp = line . codimp ( ) ;
TString8 lin = line . codlin ( ) ;
2005-03-17 18:21:37 +00:00
_artinfo . art2magimpline ( art , mag , imp , lin ) ;
2005-02-17 18:13:12 +00:00
// GUY was here with Koki
2005-03-17 18:21:37 +00:00
const long codcli = is_production_article ( art ) ? line . codclifor ( ) : 0L ;
2006-07-11 13:10:51 +00:00
const TString & rdoc_key = line . da_rdoc_key ( ) ;
2005-02-17 18:13:12 +00:00
2006-07-11 13:10:51 +00:00
TMRP_line * son = _articles . find ( art , riga . giacenza ( ) , mag , EMPTY_STRING , imp , lin , codcli , rdoc_key ) ;
1999-04-06 15:34:39 +00:00
if ( son = = NULL )
{
2006-07-11 13:10:51 +00:00
son = _articles . find ( art , riga . giacenza ( ) , mag , EMPTY_STRING , imp , lin , codcli , rdoc_key , true ) ;
1999-04-06 15:34:39 +00:00
son - > set_description ( distinta . describe ( art ) ) ;
}
2005-03-17 18:21:37 +00:00
const int son_depth = line . explosion_depth ( ) + 1 ;
if ( son_depth > son - > explosion_depth ( ) )
son - > set_explosion_depth ( son_depth ) ;
2005-03-03 15:42:04 +00:00
2005-03-17 18:21:37 +00:00
line . add_son ( riga . val ( ) , son ) ;
1999-10-22 10:00:18 +00:00
distinta . describe ( art ) ;
1999-04-06 15:34:39 +00:00
}
}
}
}
if ( pi ! = NULL ) delete pi ;
return _articles . items ( ) > 0 ;
}
/////////// finished: 100%
/////////// tested:
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : load_planned_orders ( )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
const TMatResMask & m = * _mask ;
1999-04-06 15:34:39 +00:00
TDate date_fr = m . get ( F_DADATA ) ;
const int bucket_fr = m . round_date ( date_fr , FALSE ) ;
TDate date_to = m . get ( F_ADATA ) ;
const int bucket_to = m . round_date ( date_to , TRUE ) ;
2001-05-02 13:40:49 +00:00
const int year_fr = date_fr . year ( ) - ( m . get_bool ( F_DOC_YEAR_PREC ) ? 1 : 0 ) ;
1999-04-06 15:34:39 +00:00
const int year_to = date_to . year ( ) ;
2005-05-16 23:44:23 +00:00
const bool load_evasi = m . get_bool ( F_LOAD_EVASI ) ;
1999-04-06 15:34:39 +00:00
TTable num ( " %NUM " ) ;
TCodice_numerazione cod ;
TRelation rel ( LF_DOC ) ;
TCursor cur ( & rel ) ;
const TRectype & curr = cur . curr ( ) ;
TRectype filter_fr ( curr ) , filter_to ( curr ) ;
2006-04-13 17:56:02 +00:00
const TString_array & n = m . sfield ( F_NUM_ORF ) . rows_array ( ) ;
const TString_array & a = m . sfield ( F_TIPI_ORF ) . rows_array ( ) ;
1999-04-06 15:34:39 +00:00
// Scandisce tutte le numerazioni considerando solo quelle
// contenenti i tipi documento specificati nella maschera
2006-07-11 13:10:51 +00:00
for ( int err = cod . first ( num ) ; err = = NOERR ; err = cod . next ( num ) ) if ( test_codnum ( cod , n ) )
{
// Filtra il cursore in modo da limitarlo alla numerazione
// corrente ed agli anni specificati dalle due date limite
cur . freeze ( false ) ;
filter_fr . put ( DOC_PROVV , " D " ) ;
filter_fr . put ( DOC_CODNUM , cod . codice ( ) ) ;
filter_fr . put ( DOC_ANNO , year_fr ) ;
filter_to . put ( DOC_PROVV , " D " ) ;
filter_to . put ( DOC_CODNUM , cod . codice ( ) ) ;
filter_to . put ( DOC_ANNO , year_to ) ;
cur . setregion ( filter_fr , filter_to ) ;
TString16 cfilter ;
cfilter < < DOC_CODNUM < < " == " < < ' " ' < < cod . codice ( ) < < ' " ' ;
cur . setfilter ( cfilter ) ;
const long items = cur . items ( ) ;
cur . freeze ( true ) ;
TString msg ; msg < < TR ( " Caricamento arrivi futuri " ) < < " ... ( " < < cod . codice ( ) < < ' ) ' ;
TProgind pj ( items , msg , true , true ) ;
// Scandisce i documenti inevasi e considera solo
// quelli con uno stato nel range corretto
for ( cur = 0 ; cur . pos ( ) < items ; + + cur )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
if ( ! pj . addstatus ( 1 ) )
break ;
const bool doc_evaso = curr . get_bool ( DOC_DOCEVASO ) ;
const bool evaso = ! load_evasi & & doc_evaso ;
if ( evaso )
continue ;
const int sheetrow = test_status ( curr , a ) ;
if ( sheetrow < 0 )
continue ;
// Data di consegna standard
TDate doc_cons = curr . get ( DOC_DATACONS ) ;
if ( ! doc_cons . ok ( ) )
doc_cons = curr . get_date ( DOC_DATADOC ) ;
// Scandisce le righe articolo e memorizza le quantita' richieste
const TDocumento doc ( cur . curr ( ) ) ;
for ( int r = doc . physical_rows ( ) ; r > 0 ; r - - )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
// Seleziona le righe articolo non ancora evase
const TRiga_documento & riga = doc [ r ] ;
if ( ! riga . is_articolo ( ) )
1999-04-06 15:34:39 +00:00
continue ;
2006-07-11 13:10:51 +00:00
TDate consegna = riga . get ( RDOC_DATACONS ) ;
if ( ! consegna . ok ( ) )
consegna = doc_cons ;
// Data consegna troppo avanti
if ( consegna > date_to )
1999-04-06 15:34:39 +00:00
continue ;
2006-07-11 13:10:51 +00:00
bool padre_evaso = false ;
if ( load_evasi )
{
const TRectype * dariga = riga . find_original_rdoc ( ) ;
if ( dariga ! = NULL & & dariga - > get_bool ( RDOC_RIGAEVASA ) )
{
const TRectype * dadoc = riga . find_original_doc ( ) ;
if ( dadoc ! = NULL )
padre_evaso = dadoc - > get_bool ( DOC_DOCEVASO ) ;
}
}
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
const real qta = load_evasi & & ! padre_evaso ? riga . quantita ( ) : riga . qtaresidua ( ) ;
if ( qta > ZERO )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
const TCodice_articolo art = riga . get ( RDOC_CODARTMAG ) ;
const TString16 liv = riga . get ( RDOC_LIVELLO ) ;
const TString8 mag = riga . get ( RDOC_CODMAG ) ;
const TString8 imp = riga . get ( RDOC_IMPIANTO ) ;
const TString8 lin = riga . get ( RDOC_LINEA ) ;
// GUY was Here, but it's Koki fault!
const long codcli = is_production_article ( art ) ? doc . get_long ( DOC_CODCF ) : 0 ;
TString80 rdoc_key ;
rdoc_key . format ( " %-4s%4dD%7ld%4d " ,
( const char * ) riga . get ( RDOC_DACODNUM ) , riga . get_int ( RDOC_DAANNO ) ,
riga . get_long ( RDOC_DANDOC ) , riga . get_int ( RDOC_DAIDRIGA ) ) ;
TMRP_line * line = _articles . find ( art , liv , mag , EMPTY_STRING , imp , lin , codcli , rdoc_key ) ;
if ( line = = NULL )
1999-04-06 15:34:39 +00:00
{
2006-07-11 13:10:51 +00:00
line = _articles . find ( art , liv , mag , EMPTY_STRING , imp , lin , codcli , rdoc_key , true ) ;
line - > set_description ( riga . get ( RDOC_DESCR ) ) ;
1999-04-06 15:34:39 +00:00
}
2006-07-11 13:10:51 +00:00
TPrice prz ( riga . prezzo ( TRUE , TRUE ) ) ;
const TCodice_um um = riga . get ( RDOC_UMQTA ) ;
TQuantita q ( art , um , qta ) ;
q . convert2umbase ( ) ;
q . currency2umbase ( prz ) ;
const TString4 codnum = doc . get ( DOC_CODNUM ) ;
const long docnum = doc . get_long ( DOC_NDOC ) ;
const int numriga = riga . get_int ( RDOC_NRIGA ) ;
TMRP_docref * docref = new TMRP_docref ( doc . get_int ( DOC_ANNO ) , codnum , docnum ,
numriga , um , q . val ( ) , prz . get_num ( ) ) ;
const TMRP_time t ( consegna , 0 , imp , lin ) ;
if ( has_confirmed_status ( doc , a . row ( sheetrow ) ) | |
( codnum ! = m . get ( F_NUM_PROD ) & & codnum ! = m . get ( F_NUM_FORN ) ) )
line - > add_sched_rec ( t , q . val ( ) , docref ) ;
else
line - > add_planned_ord ( t , q . val ( ) , docref ) ;
1999-04-06 15:34:39 +00:00
}
}
}
}
return _articles . items ( ) > 0L ;
}
/////////// finished: 99%
/////////// tested: 99%
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : preprocess_cycle ( )
1999-04-06 15:34:39 +00:00
{
// costruisce il gross requirement dai DOC di planning
1999-10-22 10:00:18 +00:00
bool ok = load_gross_requirements ( ) ;
1999-06-18 15:35:05 +00:00
// costruisce gli sched rec degli elementi dai DOCS ordini fornitore emessi
1999-10-22 10:00:18 +00:00
ok | = load_planned_orders ( ) ;
1999-06-18 15:35:05 +00:00
if ( ok )
2005-05-16 23:44:23 +00:00
// esplode l'array mediante la Distinta Base
1999-10-22 10:00:18 +00:00
return explode_articles ( ) ;
1999-06-18 15:35:05 +00:00
/*
// costruisce il gross requirement dai DOC di planning
if ( load_gross_requirements ( m ) )
1999-04-06 15:34:39 +00:00
// esplode l'array mediante la DIBA
if ( explode_articles ( m ) )
// costruisce gli sched rec degli elementi dai DOCS ordini fornitore emessi
1999-06-18 15:35:05 +00:00
return load_planned_orders ( m ) ;
*/
2005-05-16 23:44:23 +00:00
return false ;
}
long TMatResPlanning : : compute_production_time ( const TMRP_line & line , const real & qta ) const
{
real tot ;
if ( line . codlin ( ) . not_empty ( ) )
{
TDistinta_tree tree ;
tree . set_global ( " _MAGDEP " , line . codmagdep ( ) ) ;
tree . set_global ( " _LINEA " , line . codlin ( ) ) ;
tree . set_global ( " _IMPIANTO " , line . codimp ( ) ) ;
tree . set_root ( line . articolo ( ) , " " , qta , line . livgiac ( ) ) ;
TArray lav_array ;
for ( TRiga_esplosione * llav = tree . first_labor ( lav_array , RAGGR_EXP_UMBASE ) ; llav ;
llav = tree . next_labor ( lav_array ) )
{
TLavorazione * lavorazione = tree . find_labor ( llav ) ;
const int linea = lavorazione - > find_linea ( line . codlin ( ) ) ;
if ( linea > = 0 )
{
const real prod_linea = lavorazione - > produttiv_linea ( linea ) ;
real ore = ( llav - > val ( ) * lavorazione - > um_temporale ( ) . converti_in_ore ( ) ) / prod_linea ;
// if (carico_uomo) ore *= lavorazione->numpers_linea(linea);
tot + = ore ;
}
}
tot . ceil ( ) ;
}
return tot . integer ( ) ;
1999-04-06 15:34:39 +00:00
}
/////////// finished: 99%
/////////// tested:
// implementa la logica che porta dal fabbisogno lordo a quello netto
// per quel bucket e riporta il balance on hand sul bucket successivo
1999-10-22 10:00:18 +00:00
// ipotesi essenziale per il rescheduling: la chiamata della funzione
// deve essere fatta ciclicamente su tutti i bucket di un articolo
// prima di passare ad un altro articolo
2001-05-02 13:40:49 +00:00
bool TMatResPlanning : : gross2net_logic ( TMRP_line & curr_article , int bucket , bool & sc_used )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
const TMatResMask & m = * _mask ;
2006-07-11 13:10:51 +00:00
const TDate start_date = m . get_date ( F_DADATA ) ;
1999-10-22 10:00:18 +00:00
const bool lotsizing_p = m . get_bool ( F_LOTSIZING_P ) ;
const bool lotsizing_f = m . get_bool ( F_LOTSIZING_F ) ;
const bool use_leadtime = ! m . get_bool ( F_IGN_LDTIME ) ;
1999-04-06 15:34:39 +00:00
// Verifico se esiste gia' un fabbisogno netto
real sm , tmpreal = - curr_article . net_requirement ( bucket ) ;
if ( tmpreal > = ZERO ) // Devo calcolare il fabbisogno netto
{
tmpreal = curr_article . on_hand ( bucket ) ;
tmpreal - = curr_article . gross_requirement ( bucket ) ;
2001-05-02 13:40:49 +00:00
if ( ! sc_used )
{
curr_article . scorta_minima ( sm , curr_article . time ( bucket ) . date ( ) ) ;
2006-07-11 13:10:51 +00:00
sc_used = true ;
2001-05-02 13:40:49 +00:00
tmpreal - = sm ;
}
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
// tmpreal += curr_article.planned_orders(bucket); //planned orders are not added here, but in build orders phase
2000-05-05 15:25:49 +00:00
if ( ! m . get_bool ( F_RESCHEDULING ) )
tmpreal + = curr_article . sched_receipts ( bucket ) ; //scheduled orders are not added if we reschedule them
1999-04-06 15:34:39 +00:00
// adegua il quantitativo del fabbisogno netto in base al lot-sizing, se il valore risulta negativo
const int n_figli = curr_article . sons ( ) ;
real net_req ;
if ( ( lotsizing_p & & n_figli ! = 0 ) | | ( lotsizing_f & & n_figli = = 0 ) )
net_req = curr_article . sizeup_net_requirement ( bucket , tmpreal ) ;
else
net_req = curr_article . set_net_req ( bucket , - tmpreal ) ;
// calcola la giacenza del bucket successivo
tmpreal + = net_req ;
if ( tmpreal > ZERO )
{
const int nb = curr_article . next_bucket ( bucket ) ;
if ( nb < = curr_article . last_bucket ( ) )
curr_article . set_on_hand ( nb , tmpreal ) ;
}
// trasforma i fabbisogni totali nel fabbisogno lordo dei figli
net_req + = curr_article . sched_receipts ( bucket ) ;
1999-10-22 10:00:18 +00:00
// net_req += curr_article.planned_orders(bucket);//planned orders are not added here, but in build orders phase
2005-05-16 23:44:23 +00:00
if ( net_req > ZERO & & n_figli > 0 )
1999-04-06 15:34:39 +00:00
{
2005-05-16 23:44:23 +00:00
TMRP_time lead_time ;
1999-06-18 15:35:05 +00:00
curr_article . lead_time ( bucket , lead_time , use_leadtime ) ;
2005-05-16 23:44:23 +00:00
const int ldtime_mode = m . get_int ( F_LDTIME_MODE ) ;
if ( ldtime_mode = = 1 | | ldtime_mode = = 2 )
2000-05-05 15:25:49 +00:00
{
2005-05-16 23:44:23 +00:00
const long xtrahours = compute_production_time ( curr_article , net_req ) ;
if ( xtrahours > 0 )
{
if ( ldtime_mode = = 1 )
lead_time . sub_time ( 0 , xtrahours ) ;
else
{
TMRP_time prod_time = curr_article . time ( bucket ) ;
prod_time . sub_time ( 0 , xtrahours ) ;
if ( prod_time < lead_time )
lead_time = prod_time ;
}
}
2000-05-05 15:25:49 +00:00
}
2005-05-16 23:44:23 +00:00
const int xtradays = m . get_int ( F_XTRA_LDTIME ) ;
if ( xtradays )
lead_time . sub_time ( xtradays ) ;
1999-04-06 15:34:39 +00:00
for ( int o = 0 ; o < n_figli ; o + + )
{
TMRP_line & article_son = curr_article . son ( o ) ;
tmpreal = net_req * curr_article . qta_son ( o ) ;
2001-05-02 13:40:49 +00:00
tmpreal . round ( 5 ) ;
1999-04-06 15:34:39 +00:00
if ( tmpreal > ZERO )
1999-10-22 10:00:18 +00:00
{
TMRP_internalref * iref = new TMRP_internalref ( & curr_article , bucket , tmpreal ) ;
2005-05-16 23:44:23 +00:00
article_son . add_gross_req ( lead_time , tmpreal , iref ) ;
1999-10-22 10:00:18 +00:00
}
1999-04-06 15:34:39 +00:00
}
}
2005-05-16 23:44:23 +00:00
return true ;
1999-04-06 15:34:39 +00:00
}
/////////// finished: 99%
/////////// tested:
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : net_requirement_cycle ( )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
const TMatResMask & m = * _mask ;
2006-07-11 13:10:51 +00:00
const bool use_mag = ! m . get_bool ( F_DONT_USE_MAG ) ;
1999-10-22 10:00:18 +00:00
2005-05-16 23:44:23 +00:00
bool ok = true ;
1999-04-06 15:34:39 +00:00
// ordina gli articoli
const long total = _articles . sort ( ) ;
2006-07-11 13:10:51 +00:00
TProgind pi ( total , TR ( " Calcolo dei fabbisogni netti " ) , false , true ) ;
1999-04-06 15:34:39 +00:00
// cicla iterativamente sugli elementi di _articles
for ( long a = 0 ; a < total ; a + + )
{
pi . addstatus ( 1 ) ;
TMRP_line & curr_article = _articles [ a ] ;
const int last = curr_article . last_bucket ( ) ;
if ( last > = 0 )
{
real curgiac ;
2006-07-11 13:10:51 +00:00
if ( use_mag )
curr_article . giacenza_attuale ( curgiac , m . get_date ( F_DADATA ) ) ;
curr_article . set_on_hand ( 0 , curgiac ) ;
2001-05-02 13:40:49 +00:00
2006-07-11 13:10:51 +00:00
bool sc_used = false ;
1999-04-06 15:34:39 +00:00
for ( int bucket = 0 ; ok & & bucket < = last ; bucket = curr_article . next_bucket ( bucket ) )
{
1999-10-22 10:00:18 +00:00
// !?!?! la logica gross2net dovrebbe funzionare in termini di intervalli di date
// (bucket-utente) piuttosto che di bucket di MRPline (che possono essere pi<70> di uno
// in un intervallo, altrimenti i ragionamenti di scorte minime e lotti
// funzionano in modo sbagliato, perch<63> approssimano pi<70> volte
2001-05-02 13:40:49 +00:00
ok = gross2net_logic ( curr_article , bucket , sc_used ) ;
1999-04-06 15:34:39 +00:00
if ( ! ok )
break ;
}
}
}
return ok ;
}
/////////// finished: 100%
/////////// tested : 100%
// genera le righe degli ordini di produzione o a fornitore
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : build_orders ( )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
TMatResMask & m = * _mask ;
1999-04-06 15:34:39 +00:00
TSheet_field & sf = m . sfield ( F_ORDINI ) ;
sf . destroy ( ) ;
const long tot = _articles . items ( ) ;
if ( tot > 0L )
{
2006-07-11 13:10:51 +00:00
TProgind pi ( tot , TR ( " Generazione righe ordini... " ) , false , true ) ;
1999-04-06 15:34:39 +00:00
for ( long a = 0 ; a < tot ; a + + )
{
pi . addstatus ( 1 ) ;
const TMRP_line & line = _articles [ a ] ;
2005-02-17 18:13:12 +00:00
const bool prod = is_production_article ( line . articolo ( ) ) ;
2001-05-02 13:40:49 +00:00
long forn = 0 ;
2005-02-17 18:13:12 +00:00
if ( ! prod ) // Se l'articolo NON e' di produzione ...
2001-05-02 13:40:49 +00:00
{
2006-07-11 13:10:51 +00:00
TString80 key = line . codimp ( ) ;
2001-05-02 13:40:49 +00:00
key . rpad ( 5 ) ;
key < < line . articolo ( ) ;
2005-02-17 18:13:12 +00:00
// Cerco il fornitore specifico per l'impianto
2001-05-02 13:40:49 +00:00
forn = atol ( cache ( ) . get ( " FIA " , key , " I0 " ) ) ;
2005-02-17 18:13:12 +00:00
if ( forn = = 0L ) // Cerco il fornitore di default in anagrafica
{
const TRectype & anarec = cache ( ) . get ( LF_ANAMAG , line . articolo ( ) ) ;
2001-05-02 13:40:49 +00:00
forn = anarec . get_long ( " CODFORN " ) ;
2005-02-17 18:13:12 +00:00
}
2001-05-02 13:40:49 +00:00
}
2005-02-17 18:13:12 +00:00
else
forn = line . codclifor ( ) ; // Prendo il codice "eventualmente" proveniente dall'ordine
1999-04-06 15:34:39 +00:00
for ( int b = line . last_bucket ( ) ; b > = 0 ; b - - )
{
2002-12-20 16:15:03 +00:00
/*
1999-10-22 10:00:18 +00:00
const TMRP_record & rrr = line . record ( b ) ;
2000-05-05 15:25:49 +00:00
const real r0 = line . gross_requirement ( b ) ;
const real r1 = line . planned_orders ( b ) ;
const real r2 = line . sched_receipts ( b ) ;
1999-04-06 15:34:39 +00:00
real qta = line . net_requirement ( b ) ;
1999-10-22 10:00:18 +00:00
qta - = line . planned_orders ( b ) ;
1999-06-18 15:35:05 +00:00
qta . round ( 5 ) ;
2000-05-05 15:25:49 +00:00
if ( ! qta . is_zero ( ) | |
line . planned_orders ( b ) > 0 | |
line . sched_receipts ( b ) > line . gross_requirement ( b ) )
1999-10-22 10:00:18 +00:00
m . add_order_line ( forn , line , b ) ;
2002-12-20 16:15:03 +00:00
else
*/
2005-02-17 18:13:12 +00:00
m . add_order_line ( forn , line , b ) ;
1999-04-06 15:34:39 +00:00
}
}
}
const int orders = sf . items ( ) ;
if ( orders = = 0 )
2004-05-18 11:17:26 +00:00
message_box ( TR ( " Nessun ordine da emettere " ) ) ;
1999-04-06 15:34:39 +00:00
real price , qta ;
TCodice_articolo codart ;
FOR_EACH_SHEET_ROW ( sf , n , row )
{
1999-10-22 10:00:18 +00:00
row - > get ( F_QUANTITA - FIRST_FIELD , qta ) ;
row - > get ( F_ARTICOLO - FIRST_FIELD , codart ) ;
2006-07-11 13:10:51 +00:00
const long codcli = row - > get_long ( F_FORNITORE - FIRST_FIELD ) ;
1999-10-22 10:00:18 +00:00
const TRectype & rec = cache ( ) . get ( LF_DIST , codart ) ;
bool art_prod , art_acq ;
if ( rec . empty ( ) )
{
art_acq = TRUE ;
2005-02-17 18:13:12 +00:00
art_prod = is_production_article ( codart ) ;
}
else
{
1999-10-22 10:00:18 +00:00
art_prod = rec . get_bool ( " ARTPROD " ) ;
art_acq = rec . get_bool ( " ARTACQ " ) | | codcli ! = 0L ;
}
TString4 tipoord = art_prod ? " P " : " F " ;
row - > add ( tipoord , F_ORD_TYPE - FIRST_FIELD ) ;
1999-04-06 15:34:39 +00:00
sf . check_row ( n ) ;
if ( tipoord = = " P " )
tipoord = " " ;
else
tipoord = m . get ( F_TIPOCF_CONDV ) ;
find_price ( m . get ( F_TIPOCV ) , m . get ( F_CODCONDV ) , m . get ( F_CATVEN_CV ) ,
1999-10-22 10:00:18 +00:00
tipoord , codcli , codart , qta , price ) ;
row - > add ( price . string ( ) , F_PREZZO - FIRST_FIELD ) ;
if ( ! art_prod | | ! art_acq )
sf . disable_cell ( n , F_ORD_TYPE - FIRST_FIELD ) ;
1999-04-06 15:34:39 +00:00
}
2000-05-05 15:25:49 +00:00
sf . enable ( ! m . get_bool ( F_DISABLESAVE ) ) ;
1999-04-06 15:34:39 +00:00
return TRUE ;
}
1999-10-22 10:00:18 +00:00
/////////// finished: 0%
void TMatResPlanning : : print_orders_header ( TPrinter & pr )
{
TPrintrow row ;
print_header ( pr ) ;
2004-05-18 11:17:26 +00:00
row . put ( FR ( " @48G@BSTAMPA PROPOSTE D'ORDINE DA M.R.P. " ) ) ;
1999-10-22 10:00:18 +00:00
pr . setheaderline ( 1 , row ) ;
row . reset ( ) ;
set_body_order_line ( row , NULL ) ;
pr . setheaderline ( 3 , row ) ;
row . reset ( ) ;
row . put ( ( const char * ) TString ( 131 , ' - ' ) ) ;
pr . setheaderline ( 4 , row ) ;
}
2006-07-11 13:10:51 +00:00
1999-10-22 10:00:18 +00:00
void TMatResPlanning : : print_orders_body ( TPrinter & pr , TToken_string * sheetrow )
{
TPrintrow row ;
// riga 1
set_body_order_line ( row , sheetrow ) ;
// riga 2
pr . print ( row ) ;
row . reset ( ) ;
int pos = 31 ;
row . put ( format ( " @%dG%s " , pos , ( const char * ) sheetrow - > get ( F_DESCART - FIRST_FIELD ) ) ) ;
if ( * sheetrow - > get ( F_DOCCODNUM - FIRST_FIELD ) > ' ' )
{
2004-05-18 11:17:26 +00:00
row . put ( format ( FR ( " @%dGDocumento %s " ) , pos + = 54 + 1 , ( const char * ) sheetrow - > get ( F_DOCCODNUM - FIRST_FIELD ) ) ) ;
1999-10-22 10:00:18 +00:00
row . put ( format ( " @%dG%d " , pos + = 4 + 10 + 1 , sheetrow - > get_int ( F_DOCANNODOC - FIRST_FIELD ) ) ) ;
row . put ( format ( " @%dGn.%6ld " , pos + = 4 + 1 , sheetrow - > get_long ( F_DOCNUM - FIRST_FIELD ) ) ) ;
2004-05-18 11:17:26 +00:00
row . put ( format ( FR ( " @%dGriga %3d " ) , pos + = 2 + 6 + 1 , sheetrow - > get_int ( F_DOCNRIGA - FIRST_FIELD ) ) ) ;
1999-10-22 10:00:18 +00:00
}
pr . print ( row ) ;
}
void TMatResPlanning : : set_body_order_line ( TPrintrow & row , TToken_string * sheetrow )
{
int pos = 0 ;
row . put ( format ( " @b@%dG%1s " , pos , sheetrow ? ( const char * ) sheetrow - > get ( F_ORD_TYPE - FIRST_FIELD ) : " " ) ) ;
row . put ( format ( " @%dG%6s " , pos + = 1 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_FORNITORE - FIRST_FIELD ) : " CliFor " ) ) ;
row . put ( format ( " @%dG%s " , pos + = 6 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_DATADOC - FIRST_FIELD ) : " Data doc. " ) ) ;
row . put ( format ( " @%dG%s " , pos + = 10 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_DATACONS - FIRST_FIELD ) : " Consegna " ) ) ;
row . put ( format ( " @%dG%s " , pos + = 10 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_ARTICOLO - FIRST_FIELD ) : " Codice articolo " ) ) ;
pos + = 20 + 1 ;
for ( int l = 1 ; l < = livelli_giacenza ( ) . last_level ( ) ; l + + )
{
const int len = livelli_giacenza ( ) . code_length ( l ) ;
if ( sheetrow = = NULL )
{
if ( l = = 1 )
row . put ( format ( " @%dG%s " , pos , " Livello " ) ) ;
}
else
row . put ( format ( " @%dG%s " , pos , ( const char * ) sheetrow - > get ( F_LIV1 + l - 1 - FIRST_FIELD ) ) ) ;
pos + = len + 1 ;
}
real r ;
if ( sheetrow )
{
sheetrow - > get ( F_QUANTITA - FIRST_FIELD , r ) ;
row . put ( format ( " @%dG%18s " , pos , ( const char * ) r . string ( 18 , 5 ) ) ) ;
} else {
2004-05-18 11:17:26 +00:00
row . put ( format ( FR ( " @%dGQuantita' " ) , pos + 8 ) ) ;
1999-10-22 10:00:18 +00:00
}
row . put ( format ( " @%dG%s " , pos + = 18 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_UM - FIRST_FIELD ) : " UM " ) ) ;
if ( sheetrow )
sheetrow - > get ( F_PREZZO - FIRST_FIELD , r ) ;
2008-10-09 09:17:58 +00:00
const TPrice c ( r ) ;
1999-10-22 10:00:18 +00:00
row . put ( format ( " @%dG%18s " , pos + = 2 + 1 , sheetrow ? ( const char * ) c . string ( ) : " Prezzo " ) ) ;
row . put ( format ( " @%dG%3s " , pos + = 18 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_MAGAZZINO - FIRST_FIELD ) : " Mag. " ) ) ;
row . put ( format ( " @%dG%2s " , pos + = 3 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_DEPOSITO - FIRST_FIELD ) : " " ) ) ;
row . put ( format ( " @%dG%5s " , pos + = 2 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_CODIMP - FIRST_FIELD ) : " Imp. " ) ) ;
row . put ( format ( " @%dG%5s " , pos + = 5 + 1 , sheetrow ? ( const char * ) sheetrow - > get ( F_CODLIN - FIRST_FIELD ) : " Linea " ) ) ;
pos + = 5 + 1 ;
}
/////////// tested : 0%
// stampa le proposte d'ordine
bool TMatResPlanning : : print_orders ( )
{
TMatResMask & m = * _mask ;
TSheet_field & sf = m . sfield ( F_ORDINI ) ;
2006-07-11 13:10:51 +00:00
if ( sf . items ( ) < = 0 )
1999-10-22 10:00:18 +00:00
{
2004-05-18 11:17:26 +00:00
message_box ( TR ( " Nessun ordine da stampare " ) ) ;
1999-10-22 10:00:18 +00:00
return FALSE ;
}
TMask pmask ( " mr2100c.msk " ) ;
pmask . set ( S_LIV_RISALITA , 1 ) ;
while ( pmask . run ( ) ! = K_ESC )
{
if ( pmask . get ( S_PRINTTYPE ) [ 0 ] = = ' O ' )
{
2000-05-05 15:25:49 +00:00
print_planning ( pmask ) ;
} else {
print_exceptions ( pmask ) ;
}
}
return TRUE ;
}
bool TMatResPlanning : : print_planning ( TMask & pmask )
{
TMatResMask & m = * _mask ;
TSheet_field & sf = m . sfield ( F_ORDINI ) ;
TPrinter & pr = printer ( ) ;
pr . open ( ) ;
if ( pmask . get_bool ( S_RISALITA ) )
{
2004-05-18 11:17:26 +00:00
TIndwin ( 60 , TR ( " Ordinamento proposte per articolo/data... " ) , FALSE ) ;
2000-05-05 15:25:49 +00:00
sf . sort ( order_compareADTF ) ;
sf . force_update ( ) ;
}
pr . setheaderhandler ( print_orders_header ) ;
pr . headerlen ( 6 ) ;
pr . setfooterhandler ( print_footer ) ;
pr . footerlen ( 2 ) ;
TString last_key ;
TString key ;
FOR_EACH_SHEET_ROW ( sf , r , row )
{
if ( ! pmask . get_bool ( S_SELECTEDONLY ) | | * row - > get ( sf . cid2index ( F_SELECTED ) ) = = ' X ' )
{
key = row - > get ( sf . cid2index ( F_ARTICOLO ) ) ;
key < < row - > get ( sf . cid2index ( F_DATACONS ) ) ;
if ( last_key . blank ( ) )
last_key = key ;
print_orders_body ( pr , row ) ;
if ( pmask . get_bool ( S_RISALITA ) /*&& (key != last_key || sf.items() == r)*/ )
1999-10-22 10:00:18 +00:00
{
2000-05-05 15:25:49 +00:00
print_risalita ( * row , pmask . get_int ( S_LIV_RISALITA ) , pmask . get_bool ( S_DETT_ORDINI ) ) ;
last_key = key ;
1999-10-22 10:00:18 +00:00
}
2000-05-05 15:25:49 +00:00
if ( pmask . get_bool ( S_INTERLINEA ) )
1999-10-22 10:00:18 +00:00
{
2000-05-05 15:25:49 +00:00
TPrintrow prow ;
pr . print ( prow ) ;
1999-10-22 10:00:18 +00:00
}
}
}
2000-05-05 15:25:49 +00:00
pr . close ( ) ;
2006-07-11 13:10:51 +00:00
return true ;
1999-10-22 10:00:18 +00:00
}
2005-03-03 15:42:04 +00:00
TMRP_line * TMatResPlanning : : find_risalita_line ( TToken_string & row )
1999-10-22 10:00:18 +00:00
{
2005-03-03 15:42:04 +00:00
TSheet_field & sf = _mask - > sfield ( F_ORDINI ) ;
TCodice_articolo art ;
1999-10-22 10:00:18 +00:00
row . get ( sf . cid2index ( F_ARTICOLO ) , art ) ;
2005-03-03 15:42:04 +00:00
if ( art . blank ( ) )
return NULL ;
TString16 liv ;
1999-10-22 10:00:18 +00:00
for ( int l = livelli_giacenza ( ) . last_level ( ) ; l > = 1 ; l - - )
livelli_giacenza ( ) . pack_grpcode ( liv , row . get ( sf . cid2index ( F_LIV1 + l - 1 ) ) , l ) ;
2005-03-03 15:42:04 +00:00
TString8 mag , magc , imp , lin ;
1999-10-22 10:00:18 +00:00
add_magcode ( mag , row . get ( sf . cid2index ( F_MAGAZZINO ) ) ) ;
add_depcode ( mag , row . get ( sf . cid2index ( F_DEPOSITO ) ) ) ;
row . get ( sf . cid2index ( F_CODIMP ) , imp ) ;
row . get ( sf . cid2index ( F_CODLIN ) , lin ) ;
2005-03-03 15:42:04 +00:00
2006-07-11 13:10:51 +00:00
const long codcf = row . get_long ( sf . cid2index ( F_FORNITORE ) ) ;
TString80 rdoc_key ;
rdoc_key . format ( " %-4s%4dD%7ld%4d " ,
row . get ( sf . cid2index ( F_DACODNUM ) ) , row . get_int ( sf . cid2index ( F_DAANNO ) ) ,
row . get_long ( sf . cid2index ( F_DANUMDOC ) ) , row . get_int ( sf . cid2index ( F_DANRIGA ) ) ) ;
2005-03-03 15:42:04 +00:00
2006-07-11 13:10:51 +00:00
TMRP_line * line = NULL ;
if ( _mask - > get_bool ( F_SINGLE_DOC ) )
line = _articles . find ( art , liv , mag , magc , imp , lin , codcf , rdoc_key ) ;
if ( line = = NULL )
{
line = _articles . find ( art , liv , mag , magc , imp , lin , codcf , EMPTY_STRING ) ;
if ( line = = NULL )
{
line = _articles . find ( art , liv , mag , magc , imp , lin , 0L , EMPTY_STRING ) ; // Riprovo senza clifo
if ( line = = NULL )
{
line = _articles . find ( art , liv , mag , magc , imp , EMPTY_STRING , codcf , EMPTY_STRING ) ; // Riprovo senza linea
if ( line = = NULL )
{
line = _articles . find ( art , liv , mag , magc , EMPTY_STRING , lin , codcf , EMPTY_STRING ) ; // Riprovo senza impianto
if ( line = = NULL )
{
line = _articles . find ( art , liv , mag , magc , imp , EMPTY_STRING , 0L , EMPTY_STRING ) ; // Riprovo senza nulla
}
}
}
}
2005-03-03 15:42:04 +00:00
}
return line ;
}
bool TMatResPlanning : : print_risalita ( TToken_string & row , int ris_level , bool dett_ord )
{
TMRP_line * line = find_risalita_line ( row ) ;
if ( line ! = NULL )
{
const TSheet_field & sf = _mask - > sfield ( F_ORDINI ) ;
1999-10-22 10:00:18 +00:00
print_risalita ( * line , row . get ( sf . cid2index ( F_DATACONS ) ) , ris_level , dett_ord ) ;
2005-03-03 15:42:04 +00:00
return true ;
1999-10-22 10:00:18 +00:00
}
else
{
TPrintrow prow ;
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @32gRisalita: impossibile rintracciare la proposta originale " ) ) ) ;
2005-03-03 15:42:04 +00:00
printer ( ) . print ( prow ) ;
return false ;
1999-10-22 10:00:18 +00:00
}
}
bool TMatResPlanning : : print_risalita ( const TMRP_line & line , const TDate & date , int backlevel , bool dett_ord )
{
TPrinter & pr = printer ( ) ;
TDate todate ( date ) ;
TDate fromdate = todate ;
2005-03-17 18:21:37 +00:00
const bool isbuck0 = round_date ( fromdate ) = = 0 ;
1999-10-22 10:00:18 +00:00
round_date ( todate , TRUE ) ;
int rows = 0 ;
2000-05-05 15:25:49 +00:00
//int extraleadtime = _mask->get_int(F_XTRA_LDTIME);
1999-10-22 10:00:18 +00:00
real on_hand , lordo , netto , plan , sched ;
for ( int b = line . last_bucket ( ) ; b > = 0 ; b - - )
{
2000-05-05 15:25:49 +00:00
//TMRP_time dtime = line.record(b).time();
//if (extraleadtime && line.sons() == 0)
// dtime.sub_time(extraleadtime);
//const TDate &d = dtime.date();
1999-10-22 10:00:18 +00:00
const TDate & d = line . record ( b ) . time ( ) . date ( ) ;
if ( ( isbuck0 | | d > = fromdate ) )
{
if ( d < = todate )
{
on_hand = line . record ( b ) . on_hand ( ) ;
lordo + = line . gross_requirement ( b ) ;
netto + = line . net_requirement ( b ) ;
plan + = line . planned_orders ( b ) ;
sched + = line . sched_receipts ( b ) ;
TMRP_internalrefs * irefs = line . record ( b ) . internal_refs ( ) ;
2005-05-16 23:44:23 +00:00
if ( irefs ! = NULL )
1999-10-22 10:00:18 +00:00
{
int ir = 0 ;
while ( ir < irefs - > items ( ) )
{
TMRP_internalref & iref = irefs - > get_ref ( ir ) ;
rows + = print_internal_ref ( iref , backlevel , dett_ord ) ;
ir + + ;
}
} else {
rows + = print_gross_ref ( line , b ) ;
}
}
}
}
if ( rows = = 0 )
return FALSE ;
TPrintrow prow ;
int pos = 30 ;
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @%dg Totale fabbisogno lordo %s " ) , pos , lordo . string ( 18 , 5 ) ) ) ;
1999-10-22 10:00:18 +00:00
pr . print ( prow ) ;
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @%dg Giacenza iniziale %s " ) , pos , on_hand . string ( 18 , 5 ) ) ) ;
1999-10-22 10:00:18 +00:00
pr . print ( prow ) ;
if ( dett_ord )
{
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @%dg Ordini pianificati %s " ) , pos , plan . string ( 18 , 5 ) ) ) ;
1999-10-22 10:00:18 +00:00
pr . print ( prow ) ;
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @%dg Ordini confermati %s " ) , pos , sched . string ( 18 , 5 ) ) ) ;
1999-10-22 10:00:18 +00:00
pr . print ( prow ) ;
}
sched + = plan ;
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @%dg Totale ordinato %s " ) , pos , sched . string ( 18 , 5 ) ) ) ;
1999-10-22 10:00:18 +00:00
pr . print ( prow ) ;
netto - = plan ;
2004-05-18 11:17:26 +00:00
prow . put ( format ( FR ( " @%dg Totale da pianificare %s " ) , pos , netto . string ( 18 , 5 ) ) ) ;
1999-10-22 10:00:18 +00:00
pr . print ( prow ) ;
if ( backlevel > 1 | | backlevel < 0 )
{
prow . reset ( ) ;
pr . print ( prow ) ;
}
return TRUE ;
}
int TMatResPlanning : : print_internal_ref ( const TMRP_internalref & iref , int backlevel , bool dett_ord )
{
TPrinter & pr = printer ( ) ;
int rows = 0 ;
const TMRP_line & line = * iref . line ( ) ;
int bucket = iref . bucket ( ) ;
const TMRP_time & deliv_time = line . time ( bucket ) ;
{
TMRP_time doc_time ;
line . lead_time ( bucket , doc_time , TRUE ) ;
TDate docdate = doc_time . date ( ) ;
TToken_string dockey ;
TMRP_docrefs * gr_refs = line . record ( bucket ) . requirements_refs ( ) ;
int grref = gr_refs ? gr_refs - > items ( ) : 0 ;
TMRP_docrefs * pl_refs = line . record ( bucket ) . plans_refs ( ) ;
int plref = pl_refs ? pl_refs - > items ( ) : 0 ;
TMRP_docrefs * sr_refs = line . record ( bucket ) . scheduls_refs ( ) ;
int srref = sr_refs ? sr_refs - > items ( ) : 0 ;
real totreq = line . net_requirement ( bucket ) ;
totreq + = line . sched_receipts ( bucket ) ;
real qtaplan ( totreq ) ;
real qtareq ( totreq ) ;
do {
TCodice_um um ;
TPrintrow r1 , r2 ;
real q = iref . qta ( ) ;
TMRP_docref * docref = NULL ;
if ( grref > 0 )
docref = gr_refs - > get_ref_ptr ( - - grref ) ;
else if ( srref > 0 )
docref = sr_refs - > get_ref_ptr ( - - srref ) ;
else if ( plref > 0 )
docref = pl_refs - > get_ref_ptr ( - - plref ) ;
if ( docref )
{
dockey . add ( " D " , 0 ) ;
dockey . add ( docref - > annodoc ( ) , 1 ) ;
dockey . add ( docref - > codnumdoc ( ) , 2 ) ;
dockey . add ( docref - > numdoc ( ) , 3 ) ;
qtaplan = docref - > qta_residua ( ) ;
qtaplan . round ( 5 ) ;
TQuantita qta ( line . articolo ( ) , docref - > um ( ) , docref - > qta_residua ( ) ) ;
qta . convert2umbase ( ) ;
qtareq = qtareq - qta . val ( ) ;
qtareq . round ( 5 ) ;
// documento di rif.
docdate = cache ( ) . get ( LF_DOC , dockey ) . get ( DOC_DATADOC ) ;
2004-05-18 11:17:26 +00:00
r2 . put ( format ( FR ( " @86gDocumento %s " ) , ( const char * ) docref - > codnumdoc ( ) ) ) ;
1999-10-22 10:00:18 +00:00
r2 . put ( format ( " @101g%d " , docref - > annodoc ( ) ) ) ;
r2 . put ( format ( " @106gn.%6ld " , docref - > numdoc ( ) ) ) ;
2004-05-18 11:17:26 +00:00
r2 . put ( format ( FR ( " @115griga %3d " ) , docref - > numrig ( ) ) ) ;
1999-10-22 10:00:18 +00:00
um = docref - > um ( ) ;
}
else
{
qtaplan = qtareq ;
}
TQuantita qta ( line . articolo ( ) , um , qtaplan ) ;
r1 . put ( format ( " @9g%s " , ( const char * ) docdate . string ( ) ) ) ;
r1 . put ( format ( " @20g%s " , ( const char * ) deliv_time . date ( ) . string ( ) ) ) ;
r1 . put ( format ( " @31g%s " , ( const char * ) line . articolo ( ) ) ) ;
int pos = 52 ;
for ( int l = 1 ; l < = livelli_giacenza ( ) . last_level ( ) ; l + + )
{
r1 . put ( format ( " @%dg%s " , pos , ( const char * ) line . livgiac ( l ) ) ) ;
pos + = livelli_giacenza ( ) . code_length ( l ) + 1 ;
}
// aggiunge il fabbisogno
r1 . put ( format ( " @%dg%s " , pos + 18 + 1 + 2 + 1 , ( const char * ) qta . val ( ) . string ( 15 , 2 ) ) ) ;
r1 . put ( format ( " @%dg%s " , pos + 18 + 1 + 2 + 1 + 15 + 1 , ( const char * ) qta . um ( ) ) ) ;
qta . convert2umbase ( ) ;
q = iref . qta ( ) / totreq * qta . val ( ) ;
r1 . put ( format ( " @%dg%s " , pos , ( const char * ) q . string ( 18 , 5 ) ) ) ;
r1 . put ( format ( " @%dg%s " , pos + = 18 + 1 , ( const char * ) " \" \" " ) ) ;
pos + = 2 + 1 + 15 + 1 ;
r1 . put ( format ( " @%dg%s " , pos + = 2 + 1 , ( const char * ) line . codmag ( ) ) ) ;
r1 . put ( format ( " @%dg%s " , pos + = 3 + 1 , ( const char * ) line . coddep ( ) ) ) ;
r1 . put ( format ( " @%dg%s " , pos + = 2 + 1 , ( const char * ) line . codimp ( ) ) ) ;
r1 . put ( format ( " @%dg%s " , pos + = 5 + 1 , ( const char * ) line . codlin ( ) ) ) ;
r2 . put ( format ( " @31g%s " , ( const char * ) line . description ( ) ) ) ;
pr . print ( r1 ) ;
pr . print ( r2 ) ;
rows + + ;
} while ( ( grref > 0 | | srref > 0 | | plref > 0 ) & & qtareq > ZERO ) ;
}
if ( - - backlevel ! = 0 )
print_risalita ( line , deliv_time . date ( ) , backlevel , dett_ord ) ;
return rows ;
}
int TMatResPlanning : : print_gross_ref ( const TMRP_line & line , int bucket )
{
2005-03-17 18:21:37 +00:00
return 0 ;
// Guy: a cosa serve ????????????????????????????????????????????????
1999-10-22 10:00:18 +00:00
TPrinter & pr = printer ( ) ;
TToken_string dockey ;
real totreq , qtaplan , qtareq ;
TMRP_time deliv_time = line . time ( bucket ) ;
TMRP_time doc_time ;
line . lead_time ( bucket , doc_time , TRUE ) ;
TPrintrow r ;
2005-03-17 18:21:37 +00:00
1999-10-22 10:00:18 +00:00
TMRP_docref * docref = NULL ;
TMRP_docrefs * gr_refs = line . record ( bucket ) . requirements_refs ( ) ;
int grref = gr_refs ? gr_refs - > items ( ) : 0 ;
while ( grref )
{
docref = gr_refs - > get_ref_ptr ( - - grref ) ;
qtaplan = docref - > qta_residua ( ) ;
qtaplan . round ( 5 ) ;
dockey . add ( " D " , 0 ) ;
dockey . add ( docref - > annodoc ( ) , 1 ) ;
dockey . add ( docref - > codnumdoc ( ) , 2 ) ;
dockey . add ( docref - > numdoc ( ) , 3 ) ;
// data del documento di rif.
//r.put(format("", add(cache().get(LF_DOC,dockey).get(DOC_DATADOC)));
r . put ( format ( " @82g%d " , docref - > annodoc ( ) ) ) ;
r . put ( format ( " @86g%s " , ( const char * ) docref - > codnumdoc ( ) ) ) ;
r . put ( format ( " @90g%ld " , docref - > numdoc ( ) ) ) ;
r . put ( format ( " @100g%riga n.d " , docref - > numrig ( ) ) ) ;
//r.put(format("", deliv_time.date().string());
const TCodice_um um_nulla ;
const TQuantita qta ( line . articolo ( ) , docref - > um ( ) , qtaplan ) ;
r . put ( format ( " @10g%s " , ( const char * ) qta . val ( ) . string ( ) ) ) ;
r . put ( format ( " @30g%s " , ( const char * ) qta . um ( ) ) ) ;
r . put ( format ( " @50g%s " , ( const char * ) qtaplan . string ( ) ) ) ;
r . put ( format ( " @70g%s " , ( const char * ) qta . um ( ) ) ) ;
}
return 0 ;
}
2000-10-03 13:45:12 +00:00
void TMatResPlanning : : save_orders ( TAssoc_array & docs )
{
TMatResMask & m = * _mask ;
FOR_EACH_ASSOC_OBJECT ( docs , hash , str , obj )
{
TDocumento & doc = ( TDocumento & ) * obj ;
int err ;
if ( doc . get_long ( DOC_NDOC ) )
{
// riscrittura; elimina righe con qta zero
2005-05-16 23:44:23 +00:00
// if (!m.get_bool(F_ALL_ORDERSCHANGES))
int nrows = doc . physical_rows ( ) ;
for ( int numriga = nrows ; numriga > 0 ; numriga - - )
{
if ( doc [ numriga ] . get_real ( RDOC_QTA ) . is_zero ( ) )
doc . destroy_row ( numriga , TRUE ) ;
}
nrows = doc . physical_rows ( ) ;
if ( nrows > 0 )
err = doc . rewrite ( ) ;
else
{
TDocumento d ;
if ( d . read ( doc , _isequal , _testandlock ) = = NOERR )
d . remove ( ) ;
}
2000-10-03 13:45:12 +00:00
}
else
// generazione
err = doc . write ( ) ;
if ( err ! = NOERR )
doc . read ( ) ; // unlock
}
docs . destroy ( ) ;
}
bool TMatResPlanning : : ask_save ( )
{
TMatResMask & m = * _mask ;
TSheet_field & sf = m . sfield ( F_ORDINI ) ;
int tot = 0 ;
FOR_EACH_SHEET_ROW ( sf , r , row )
{
TToken_string & riga = * row ;
if ( * riga . get ( 0 ) = = ' X ' )
tot + + ;
}
bool yes = TRUE ;
if ( tot > 0 )
2004-05-18 11:17:26 +00:00
yes = yesno_box ( FR ( " Si desidera elaborare %d righe? " ) , tot ) ;
2000-10-03 13:45:12 +00:00
return yes ;
}
1999-10-22 10:00:18 +00:00
2005-03-03 15:42:04 +00:00
const TRectype * TMatResPlanning : : irefs2rdoc ( const TMRP_internalrefs & irefs ) const
{
const TRectype * rdoc = NULL ;
for ( int i = irefs . items ( ) - 1 ; i > = 0 & & rdoc = = NULL ; i - - )
{
const TMRP_internalref & iref = irefs . get_ref ( i ) ;
const TMRP_line & line = * iref . line ( ) ;
const int bucket = iref . bucket ( ) ;
const TMRP_record & rec = line . record ( bucket ) ;
for ( int i = 0 ; i < 3 & & rdoc = = NULL ; i + + )
{
TMRP_docrefs * refs = NULL ;
switch ( i )
{
case 0 : refs = rec . requirements_refs ( ) ; break ;
case 1 : refs = rec . plans_refs ( ) ; break ;
case 2 : refs = rec . scheduls_refs ( ) ; break ;
default : break ;
}
if ( refs ! = NULL & & refs - > items ( ) > 0 )
{
2005-03-17 18:21:37 +00:00
for ( int j = refs - > last ( ) ; j > = 0 ; j - - )
{
const TMRP_docref & docref = * refs - > get_ref_ptr ( j ) ;
if ( docref . numrig ( ) > 0 )
2005-05-16 23:44:23 +00:00
{
2005-03-17 18:21:37 +00:00
rdoc = & docref . get_rdoc ( ) ;
2005-05-16 23:44:23 +00:00
break ;
}
2005-03-17 18:21:37 +00:00
}
2005-03-03 15:42:04 +00:00
}
}
2005-03-17 18:21:37 +00:00
2005-05-16 23:44:23 +00:00
// Qui comincia la magia, perche' differente dalla risalita standard
2005-03-17 18:21:37 +00:00
if ( rdoc = = NULL )
{
const TMRP_internalrefs * inter = rec . internal_refs ( ) ;
if ( inter ! = NULL & & inter - > items ( ) > 0 )
rdoc = irefs2rdoc ( * inter ) ;
}
2005-03-03 15:42:04 +00:00
}
return rdoc ;
}
2006-07-11 13:10:51 +00:00
const TRectype * TMatResPlanning : : trova_da_rdoc ( const TMRP_line & line , const TDate & datacon ) const
{
const TRectype * dardoc = NULL ;
// Cerco la riga di risalita
const int last_bucket = line . last_bucket ( ) ;
for ( int bucket = last_bucket ; bucket > = 0 ; bucket - - )
{
const TMRP_record & buck = line . record ( bucket ) ;
if ( datacon > = buck . time ( ) . date ( ) )
{
TMRP_internalrefs * irefs = buck . internal_refs ( ) ;
if ( irefs ! = NULL & & irefs - > items ( ) > 0 )
{
dardoc = irefs2rdoc ( * irefs ) ;
}
if ( dardoc = = NULL )
{
TMRP_docrefs * gr_refs = buck . requirements_refs ( ) ;
if ( gr_refs ! = NULL & & gr_refs - > items ( ) > 0 ) // Esiste almeno una riga di risalita
{
const TMRP_docref & docref = * gr_refs - > get_ref_ptr ( 0 ) ;
dardoc = & docref . get_rdoc ( ) ;
break ;
}
}
else
break ;
}
}
return dardoc ;
}
1999-04-06 15:34:39 +00:00
/////////// finished: 90%
2005-03-03 15:42:04 +00:00
/////////// tested : 10%
1999-04-06 15:34:39 +00:00
// genera gli ordini di produzione o a fornitore
1999-10-22 10:00:18 +00:00
bool TMatResPlanning : : emit_orders ( )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
TMatResMask & m = * _mask ;
1999-04-06 15:34:39 +00:00
TSheet_field & sf = m . sfield ( F_ORDINI ) ;
1999-10-22 10:00:18 +00:00
const bool divide_by_date = m . get_bool ( F_DIVIDEBYDATE ) ;
const bool divide_by_art = m . get_bool ( F_DIVIDEBYART ) ;
TTipo_documento tipo_doc_forn ( m . get ( F_TIPO_FORN ) ) ;
TTipo_documento tipo_doc_prod ( m . get ( F_TIPO_PROD ) ) ;
1999-04-06 15:34:39 +00:00
TDate today ( TODAY ) ;
int docf = 0 , docp = 0 ;
TAssoc_array docs ;
TToken_string key ;
2000-10-03 13:45:12 +00:00
int ignore_docdate_too_soon = 0 ;
int ignore_duedate_lt_docdate = 0 ;
if ( ! ask_save ( ) )
return FALSE ;
2004-05-18 11:17:26 +00:00
TProgind pi ( sf . items ( ) , TR ( " Generazione ordini " ) , FALSE , TRUE ) ;
2000-10-03 13:45:12 +00:00
1999-04-06 15:34:39 +00:00
FOR_EACH_SHEET_ROW ( sf , r , row )
{
2000-10-03 13:45:12 +00:00
pi . addstatus ( 1 ) ;
1999-04-06 15:34:39 +00:00
TToken_string & riga = * row ;
2006-07-11 13:10:51 +00:00
if ( riga [ 0 ] = = ' X ' )
1999-04-06 15:34:39 +00:00
{
2005-03-03 15:42:04 +00:00
bool ok = true ;
1999-10-22 10:00:18 +00:00
const bool newdoc = riga . get_long ( F_DOCNUM - FIRST_FIELD ) = = 0L ;
1999-04-06 15:34:39 +00:00
const TDate datadoc = riga . get ( sf . cid2index ( F_DATADOC ) ) ;
const TDate datacon = riga . get ( sf . cid2index ( F_DATACONS ) ) ;
const char type = riga . get_char ( sf . cid2index ( F_ORD_TYPE ) ) ;
const bool prod = type = = ' P ' ;
2005-02-17 18:13:12 +00:00
const long forn = riga . get_long ( sf . cid2index ( F_FORNITORE ) ) ;
1999-10-22 10:00:18 +00:00
const long numdoc = riga . get_long ( sf . cid2index ( F_DOCNUM ) ) ;
real qta ( riga . get ( sf . cid2index ( F_QUANTITA ) ) ) ;
2006-07-11 13:10:51 +00:00
const TString4 realcodnum = riga . get ( sf . cid2index ( F_DOCCODNUM ) ) ;
1999-04-06 15:34:39 +00:00
riga . add ( " " , sf . cid2index ( F_OK ) ) ;
if ( qta . is_zero ( ) )
continue ;
1999-10-22 10:00:18 +00:00
if ( datadoc < today & & newdoc )
2000-10-03 13:45:12 +00:00
if ( ignore_docdate_too_soon ! = K_ENTER & & ignore_docdate_too_soon ! = K_ESC )
{
2004-05-18 11:17:26 +00:00
TYesnoallnone_box b ( format ( FR ( " Riga %d: data di emissione del documento (%s) inferiore a quella odierna . Confermare ? " ),r+1,(const char *)datadoc.string()), K_NO) ;
2000-10-03 13:45:12 +00:00
ignore_docdate_too_soon = b . run ( ) ;
}
if ( ignore_docdate_too_soon = = K_NO | | ignore_docdate_too_soon = = K_ESC )
1999-04-06 15:34:39 +00:00
continue ;
1999-10-22 10:00:18 +00:00
if ( datacon < datadoc & & newdoc )
2000-10-03 13:45:12 +00:00
if ( ignore_duedate_lt_docdate ! = K_ENTER & & ignore_duedate_lt_docdate ! = K_ESC )
{
2004-05-18 11:17:26 +00:00
TYesnoallnone_box b ( format ( FR ( " Riga %d: data di consegna (%s) inferiore a quella di emissione del documento ( % s ) . Confermare ? " ),r+1,(const char *)datacon.string(), (const char *)datadoc.string()), K_NO) ;
2000-10-03 13:45:12 +00:00
ignore_duedate_lt_docdate = b . run ( ) ;
}
if ( ignore_duedate_lt_docdate = = K_NO | | ignore_duedate_lt_docdate = = K_ESC )
1999-04-06 15:34:39 +00:00
continue ;
1999-10-22 10:00:18 +00:00
if ( forn = = 0L & & newdoc )
{
if ( ( prod & & ! tipo_doc_prod . clifo_optional ( ) ) | |
( ! prod & & ! tipo_doc_forn . clifo_optional ( ) ) )
{
2004-05-18 11:17:26 +00:00
error_box ( FR ( " Codice fornitore mancante alla riga %d " ) , r + 1 ) ;
1999-10-22 10:00:18 +00:00
continue ;
}
}
key . cut ( 0 ) ;
if ( newdoc )
1999-04-06 15:34:39 +00:00
{
key . add ( type ) ;
key . add ( forn ) ;
1999-10-22 10:00:18 +00:00
key . add ( datadoc . string ( ) ) ;
key . add ( divide_by_date ? datacon . string ( ) : " " ) ;
key . add ( divide_by_art ? riga . get ( sf . cid2index ( F_ARTICOLO ) ) : " " ) ;
2000-10-03 13:45:12 +00:00
}
else
{
1999-10-22 10:00:18 +00:00
key . format ( " %c%ld " , prod ? ' P ' : ' F ' , numdoc ) ;
}
TDocumento * doc = ( TDocumento * ) docs . objptr ( key ) ;
if ( doc = = NULL )
{
2000-10-03 13:45:12 +00:00
if ( docs . items ( ) > = 200 )
save_orders ( docs ) ;
2006-07-11 13:10:51 +00:00
TString4 codnum = m . get ( prod ? F_NUM_PROD : F_NUM_FORN ) ;
1999-10-22 10:00:18 +00:00
const TString & tipdoc = m . get ( prod ? F_TIPO_PROD : F_TIPO_FORN ) ;
2001-06-25 10:41:20 +00:00
if ( numdoc )
{
if ( codnum ! = realcodnum )
codnum = realcodnum ;
}
1999-10-22 10:00:18 +00:00
doc = new TDocumento ( ' D ' , datadoc . year ( ) , codnum , 0 ) ;
doc - > set_tipo ( tipdoc ) ;
TRectype & testata = doc - > head ( ) ;
if ( numdoc )
{
doc - > put ( DOC_NDOC , numdoc ) ;
ok = doc - > read ( ) = = NOERR ;
}
else
1999-04-06 15:34:39 +00:00
{
testata . put ( DOC_DATADOC , datadoc ) ;
1999-10-22 10:00:18 +00:00
testata . put ( DOC_DATACONS , divide_by_date ? datacon : datadoc ) ;
}
if ( ok )
{
1999-04-06 15:34:39 +00:00
if ( prod )
2000-10-03 13:45:12 +00:00
{
2005-02-17 18:13:12 +00:00
testata . put ( DOC_TIPOCF , doc - > tipo ( ) . tipocf ( ) ) ; // Puo' essere C o F
testata . put ( DOC_CODCF , forn ) ;
1999-04-06 15:34:39 +00:00
docp + + ;
2000-10-03 13:45:12 +00:00
}
1999-04-06 15:34:39 +00:00
else
{
testata . put ( DOC_TIPOCF , " F " ) ;
testata . put ( DOC_CODCF , forn ) ;
docf + + ;
}
2001-05-02 13:40:49 +00:00
testata . put ( DOC_CAUSMAG , doc - > tipo ( ) . caus_mov ( ) ) ;
1999-04-06 15:34:39 +00:00
docs . add ( key , doc ) ;
}
1999-10-22 10:00:18 +00:00
}
if ( ok )
{
2006-07-11 13:10:51 +00:00
const int numriga = riga . get_int ( sf . cid2index ( F_DOCNRIGA ) ) ;
1999-10-22 10:00:18 +00:00
TRiga_documento & rdoc = numdoc ? ( * doc ) [ numriga ] : doc - > new_row ( m . get ( prod ? F_RIGA_PROD : F_RIGA_FORN ) ) ;
if ( numdoc )
qta + = rdoc . get_real ( RDOC_QTA ) ;
1999-04-06 15:34:39 +00:00
rdoc . put ( RDOC_CODART , riga . get ( sf . cid2index ( F_ARTICOLO ) ) ) ;
1999-10-22 10:00:18 +00:00
1999-04-06 15:34:39 +00:00
TString80 str ;
2005-05-16 23:44:23 +00:00
for ( int l = livelli_giacenza ( ) . last_level ( ) ; l > 0 ; l - - )
1999-10-22 10:00:18 +00:00
livelli_giacenza ( ) . pack_grpcode ( str , riga . get ( sf . cid2index ( F_LIV1 + l - 1 ) ) , l ) ;
1999-04-06 15:34:39 +00:00
rdoc . put ( RDOC_LIVELLO , str ) ;
1999-10-22 10:00:18 +00:00
1999-04-06 15:34:39 +00:00
add_magcode ( str , riga . get ( sf . cid2index ( F_MAGAZZINO ) ) ) ;
add_depcode ( str , riga . get ( sf . cid2index ( F_DEPOSITO ) ) ) ;
rdoc . put ( RDOC_CODMAG , str ) ;
1999-10-22 10:00:18 +00:00
1999-04-06 15:34:39 +00:00
rdoc . put ( RDOC_IMPIANTO , riga . get ( sf . cid2index ( F_CODIMP ) ) ) ;
rdoc . put ( RDOC_LINEA , riga . get ( sf . cid2index ( F_CODLIN ) ) ) ;
rdoc . put ( RDOC_QTA , qta ) ;
1999-10-22 10:00:18 +00:00
1999-04-06 15:34:39 +00:00
rdoc . put ( RDOC_UMQTA , riga . get ( sf . cid2index ( F_UM ) ) ) ;
rdoc . put ( RDOC_PREZZO , riga . get ( sf . cid2index ( F_PREZZO ) ) ) ;
rdoc . put ( RDOC_DESCR , riga . get ( sf . cid2index ( F_DESCART ) ) ) ;
1999-10-22 10:00:18 +00:00
if ( ! divide_by_date )
rdoc . put ( RDOC_DATACONS , datacon . string ( ) ) ;
2002-12-20 16:15:03 +00:00
2005-03-03 15:42:04 +00:00
// Cerca il codice di assoggettamento fiscale sul fornitore
2002-12-20 16:15:03 +00:00
TString16 cod ;
if ( forn > 0 )
{
cod . format ( " F|%ld " , forn ) ;
cod = cache ( ) . get ( LF_CFVEN , cod , CFV_ASSFIS ) ;
}
2005-03-03 15:42:04 +00:00
// Se non lo trova lo cerca sull'articolo
2002-12-20 16:15:03 +00:00
if ( cod . empty ( ) )
cod = cache ( ) . get ( LF_ANAMAG , riga . get ( sf . cid2index ( F_ARTICOLO ) ) , ANAMAG_CODIVA ) ;
rdoc . put ( RDOC_CODIVA , cod ) ;
1999-10-22 10:00:18 +00:00
1999-04-06 15:34:39 +00:00
riga . add ( " X " , sf . cid2index ( F_OK ) ) ;
2005-03-03 15:42:04 +00:00
// Cerca di impostare la riga di provenienza dell'ordine
2005-05-16 23:44:23 +00:00
if ( rdoc . get ( RDOC_DAPROVV ) . blank ( ) ) // Se e' una riga nuova ...
2005-03-03 15:42:04 +00:00
{
2005-05-16 23:44:23 +00:00
TMRP_line * line = find_risalita_line ( riga ) ; // ... cerco la riga di risalita
2005-03-03 15:42:04 +00:00
if ( line ! = NULL )
{
2005-03-17 18:21:37 +00:00
const int depth = line - > explosion_depth ( ) + 1 ; // Profondita' esplosione (+1 per non avere zeri)
rdoc . put ( RDOC_QTAGG5 , depth ) ; // Per ora memorizziamo in QTAGG5, scelto a caso
2006-07-11 13:10:51 +00:00
const TRectype * dardoc = trova_da_rdoc ( * line , datacon ) ;
if ( dardoc ! = NULL )
{
int rifdepth = m . get_int ( F_RIFERIMENTO_MRP ) ;
2009-02-14 17:13:09 +00:00
if ( rifdepth = = 0 & & dardoc - > get ( RDOC_DACODNUM ) . full ( ) )
{
2008-11-14 00:40:30 +00:00
// rifdepth = 1;
2009-02-14 17:13:09 +00:00
const TString_array & n = m . sfield ( F_NUM_ORC ) . rows_array ( ) ;
while ( dardoc ! = NULL )
{
const TString & codnum = dardoc - > get ( RDOC_CODNUM ) ;
if ( test_codnum ( codnum , n ) )
break ;
dardoc = ( ( const TRiga_documento * ) dardoc ) - > find_original_rdoc ( ) ;
}
}
if ( dardoc ! = NULL )
rdoc . set_original_rdoc_key ( * dardoc , rifdepth ) ; // Imposto DAPROVV, DAANNO, DACODNUM, DANDOC, DAIDRIGA
else
{
TString80 msg ; msg . format ( FR ( " Riferimento non trovato: riga %d " ) , r + 1 ) ;
2009-02-15 23:43:40 +00:00
xvtil_statbar_set ( msg ) ;
2009-02-14 17:13:09 +00:00
beep ( ) ;
}
2005-05-16 23:44:23 +00:00
}
else
2005-03-03 15:42:04 +00:00
{
2005-05-16 23:44:23 +00:00
TString80 msg ; msg . format ( FR ( " Riferimento non trovato: riga %d " ) , r + 1 ) ;
2006-07-12 09:56:45 +00:00
xvtil_statbar_set ( msg ) ;
2005-05-16 23:44:23 +00:00
beep ( ) ;
2005-03-03 15:42:04 +00:00
}
}
2005-05-16 23:44:23 +00:00
else
{
TString80 msg ; msg . format ( FR ( " Linea risalita non trovata: riga %d " ) , r + 1 ) ;
2006-07-12 09:56:45 +00:00
xvtil_statbar_set ( msg ) ;
2005-05-16 23:44:23 +00:00
beep ( ) ;
}
2005-03-03 15:42:04 +00:00
}
1999-04-06 15:34:39 +00:00
}
}
}
2000-10-03 13:45:12 +00:00
save_orders ( docs ) ;
if ( sf . items ( ) )
2000-05-05 15:25:49 +00:00
{
1999-04-06 15:34:39 +00:00
FOR_EACH_SHEET_ROW_BACK ( sf , r , row )
{
2000-10-03 13:45:12 +00:00
if ( ( * row - > get ( sf . cid2index ( F_SELECTED ) ) = = ' X ' & & * row - > get ( sf . cid2index ( F_OK ) ) = = ' X ' )
| | real ( row - > get ( sf . cid2index ( F_QUANTITA ) ) ) . is_zero ( ) )
1999-10-22 10:00:18 +00:00
{
2000-10-03 13:45:12 +00:00
if ( m . get_bool ( F_ALL_ORDERSCHANGES ) )
1999-10-22 10:00:18 +00:00
row - > add ( " " , sf . cid2index ( F_QUANTITA ) ) ;
else
2000-10-03 13:45:12 +00:00
sf . destroy ( r , FALSE ) ;
1999-10-22 10:00:18 +00:00
}
1999-04-06 15:34:39 +00:00
}
2000-10-03 13:45:12 +00:00
sf . force_update ( ) ;
1999-04-06 15:34:39 +00:00
}
2000-10-03 13:45:12 +00:00
m . enable ( DLG_SAVEREC , sf . items ( ) > 0 ) ;
1999-04-06 15:34:39 +00:00
2000-10-03 13:45:12 +00:00
return TRUE ;
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
void TMatResPlanning : : compute ( )
{
if ( preprocess_cycle ( ) ) // req iniziale dai docs
if ( net_requirement_cycle ( ) )
build_orders ( ) ;
}
void TMatResPlanning : : risalita ( const TMask & m )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
TSheet_field & sf = m . sfield ( F_ORDINI ) ;
2005-03-03 15:42:04 +00:00
TToken_string & row = sf . row ( sf . selected ( ) ) ;
1999-10-22 10:00:18 +00:00
2005-03-03 15:42:04 +00:00
TCodice_articolo art ;
row . get ( sf . cid2index ( F_ARTICOLO ) , art ) ;
1999-10-22 10:00:18 +00:00
if ( art . blank ( ) )
return ;
2005-03-03 15:42:04 +00:00
TMRP_line * line = find_risalita_line ( row ) ;
if ( line ! = NULL )
1999-10-22 10:00:18 +00:00
{
TDate todate ( row . get ( sf . cid2index ( F_DATACONS ) ) ) ;
TDate fromdate = todate ;
round_date ( fromdate ) ;
round_date ( todate , TRUE ) ;
2000-05-05 15:25:49 +00:00
1999-10-22 10:00:18 +00:00
TRisalita_mask * rismask ;
2000-05-05 15:25:49 +00:00
rismask = new TRisalita_mask ( line , fromdate , todate , fromdate < = _mask - > get_date ( F_DADATA ) , _mask - > get_int ( F_XTRA_LDTIME ) ) ;
1999-10-22 10:00:18 +00:00
rismask - > run ( ) ;
delete rismask ;
2005-03-03 15:42:04 +00:00
}
else
2004-05-18 11:17:26 +00:00
message_box ( TR ( " Impossibile rintracciare la riga d'ordine indicata tra quelle generate in MRP " ) ) ;
1999-04-06 15:34:39 +00:00
}
2000-05-05 15:25:49 +00:00
bool TMatResPlanning : : print_exceptions ( TMask & m )
{
TExceptions_array e ;
bool anticipi = m . get_bool ( S_HURRYUP_EXCEPT ) ;
bool posticipi = m . get_bool ( S_DELAY_EXCEPT ) ;
bool extra = m . get_bool ( S_EXTRA_EXCEPT ) ;
if ( _articles . items ( ) > 0 )
{
// PER OGNI ARTICOLO ...
const long max_mrp_rows = _articles . items ( ) ;
2004-05-18 11:17:26 +00:00
TProgind pi = ( ( max_mrp_rows + 1 ) , TR ( " Ricerca eccezioni... " ) , TRUE , TRUE ) ;
2000-05-05 15:25:49 +00:00
for ( long mrp_row = 0 ; mrp_row < max_mrp_rows ; mrp_row + + )
{
pi . addstatus ( 1 ) ;
if ( pi . iscancelled ( ) )
return FALSE ;
TMRP_line & mrpline = _articles [ mrp_row ] ;
mrpline . reset_excepts ( ) ;
mrpline . find_ad_excepts ( anticipi , posticipi , e ) ;
if ( extra )
mrpline . find_extra_excepts ( _mask - > get_bool ( F_DIVIDEBYART ) | | _mask - > get_bool ( F_DIVIDEBYDATE ) , e ) ;
} // ... for each article
}
if ( e . items ( ) < = 0 )
2004-05-18 11:17:26 +00:00
message_box ( TR ( " Nessuna eccezione rilevata " ) ) ;
2000-05-05 15:25:49 +00:00
else
print_exceptions ( e ) ;
return e . items ( ) > 0 ;
}
void TMatResPlanning : : print_except_header ( TPrinter & pr )
{
TString format ;
TPrintrow row ;
print_header ( pr ) ;
2004-05-18 11:17:26 +00:00
row . put ( FR ( " @48G@BSTAMPA TABULATO ECCEZIONI DA M.R.P. " ) ) ;
2000-05-05 15:25:49 +00:00
pr . setheaderline ( 1 , row ) ;
row . reset ( ) ;
row . put ( ( const char * ) TString ( 131 , ' - ' ) ) ;
pr . setheaderline ( 4 , row ) ;
}
void TMatResPlanning : : print_exceptions ( TExceptions_array & excepts )
{
if ( excepts . items ( ) )
{
TPrinter & pr = printer ( ) ;
pr . open ( ) ;
pr . setheaderhandler ( print_except_header ) ;
pr . headerlen ( 6 ) ;
pr . setfooterhandler ( print_footer ) ;
pr . footerlen ( 2 ) ;
TString_array keys ;
TToken_string key , lastkey ;
TString tmp ;
excepts . get_keys ( keys ) ;
keys . sort ( ) ;
int header = 0 ;
for ( int k = 0 ; k < keys . items ( ) ; k + + )
{
key = keys . row ( k ) ;
key . get ( 0 , tmp ) ;
if ( tmp ! = lastkey . get ( 0 ) )
header = 0 ;
else if ( key . get ( 1 , tmp ) & & tmp ! = lastkey . get ( 1 ) )
header = 0 ;
else if ( key . get ( 2 , tmp ) & & tmp ! = lastkey . get ( 2 ) )
header = 1 ;
else
header = 2 ;
const TException & e = ( const TException & ) excepts [ key ] ;
const TMRP_line & line = e . mrpline ( ) ;
line . print_exception ( e . from ( ) , e . to ( ) , e . qta ( ) , header ) ;
lastkey = key ;
}
pr . close ( ) ;
}
}
2001-07-24 13:28:55 +00:00
bool TMatResPlanning : : menu ( MENU_TAG mt )
{
bool ok = TRUE ;
2009-02-24 14:21:14 +00:00
if ( mt = = MENU_ITEM_ID ( 1 ) )
2001-07-24 13:28:55 +00:00
_mask - > sel ( ) . run ( ) ;
else
ok = TSkeleton_application : : menu ( mt ) ;
return ok ;
}
2000-05-05 15:25:49 +00:00
1999-04-06 15:34:39 +00:00
void TMatResPlanning : : main_loop ( )
{
2005-09-19 12:45:16 +00:00
open_files ( LF_TABCOM , LF_TAB , LF_DOC , LF_RIGHEDOC , LF_CLIFO , LF_CFVEN , LF_OCCAS , LF_INDSP , LF_CONDV ,
LF_ANAMAG , LF_DIST , LF_RDIST , LF_MAG , LF_STOMAG , LF_DESLIN , LF_CODCORR , 0 ) ;
1999-04-06 15:34:39 +00:00
2006-07-11 13:10:51 +00:00
TSheet_field : : set_line_number_width ( 4 ) ; // Allarga numeri di riga (default = 3)
1999-10-22 10:00:18 +00:00
_mask = new TMatResMask ;
2005-02-17 18:13:12 +00:00
// Graffe necessarie per chiudere TConfig prassid
1999-04-06 15:34:39 +00:00
{
2005-02-17 18:13:12 +00:00
TConfig prassid ( CONFIG_DITTA , " ve " ) ; // apre il file di configurazione della ditta corrente
if ( prassid . get_bool ( " GES " , NULL , A_LISTINI ) )
{
_mask - > enable ( F_CATVEN_CV , prassid . get_bool ( " GESLISCV " ) ) ;
}
else
{
_mask - > disable ( F_TIPOCV ) ;
_mask - > disable ( F_CATVEN_CV ) ;
}
2006-07-11 13:10:51 +00:00
if ( ! prassid . get_bool ( " GES " , NULL , A_CONTRATTI ) | | ! prassid . get_bool ( " GESCONCC " ) )
_mask - > disable ( F_TIPOCF_CONDV ) ;
1999-04-06 15:34:39 +00:00
}
2005-02-17 18:13:12 +00:00
if ( argc ( ) > = 2 )
1999-04-06 15:34:39 +00:00
{
2005-02-17 18:13:12 +00:00
TString param = argv ( 2 ) ;
param . upper ( ) ;
if ( param . find ( " AUTO " ) > 0 ) // Lancia elaborazione batch (AUTOC o AUTOR)
_mask - > send_key ( K_CTRL + ' L ' , 0 ) ; // Preme tasto ricalcola
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
while ( _mask - > run ( ) ! = K_QUIT ) ;
delete _mask ;
2006-07-11 13:10:51 +00:00
_mask = NULL ;
1999-10-22 10:00:18 +00:00
}
1999-04-06 15:34:39 +00:00
1999-10-22 10:00:18 +00:00
void print_header ( TPrinter & pr )
{
TPrintrow row ;
2006-07-11 13:10:51 +00:00
const TRectype & firm = cache ( ) . get ( LF_NDITTE , main_app ( ) . get_firm ( ) ) ;
TString16 key ; key . format ( " %s|%s " , ( const char * ) firm . get ( NDT_TIPOA ) , ( const char * ) firm . get ( NDT_CODANAGR ) ) ;
const TString & anag = cache ( ) . get ( LF_ANAG , key , ANA_RAGSOC ) ;
2004-05-18 11:17:26 +00:00
2006-07-11 13:10:51 +00:00
TString format ;
format < < " @2g " < < anag < < " @80g@>@110gPagina @# " ;
1999-10-22 10:00:18 +00:00
row . put ( format ) ;
pr . setheaderline ( 0 , row ) ;
}
2002-12-20 16:15:03 +00:00
1999-10-22 10:00:18 +00:00
void print_footer ( TPrinter & pr )
{
TPrintrow row ;
pr . setfooterline ( 1 , row ) ;
1999-04-06 15:34:39 +00:00
}
int mr2100 ( int argc , char * argv [ ] )
{
TMatResPlanning a ;
2000-10-03 13:45:12 +00:00
2004-05-18 11:17:26 +00:00
a . run ( argc , argv , TR ( " Material Requirements Planning " ) ) ;
1999-04-06 15:34:39 +00:00
return 0 ;
}
2008-06-11 10:58:17 +00:00