Files correlati : lv4.exe lv4900a.msk lv4900.rep Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@22538 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			194 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			194 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <currency.h>
 | 
						|
#include <lffiles.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <report.h>
 | 
						|
 | 
						|
#include "lv4900a.h"
 | 
						|
#include "lvrcondv.h"
 | 
						|
 | 
						|
////////////////
 | 
						|
//  MASCHERA  //
 | 
						|
////////////////
 | 
						|
 | 
						|
class TPrezzi_mask : public TAutomask
 | 
						|
{
 | 
						|
private:  
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TPrezzi_mask() : TAutomask("lv4900a") { TPrice p; set(F_DECIMALS, p.decimals()); }
 | 
						|
};
 | 
						|
 | 
						|
bool TPrezzi_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{  
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_DATA:
 | 
						|
    if (e == fe_init && o.empty())
 | 
						|
    {
 | 
						|
      const TDate oggi(TODAY);
 | 
						|
      const int curr_month = oggi.month();
 | 
						|
      const int next_month = (((curr_month+2) % 12) / 3 * 3)+1;
 | 
						|
      const int next_year = oggi.year() + (next_month < curr_month ? 1 : 0);
 | 
						|
      const TDate d(1, next_month, next_year);
 | 
						|
      o.set(d.string());
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return true;  
 | 
						|
}
 | 
						|
 | 
						|
////////////////////////
 | 
						|
//  TPrice_recordset  //
 | 
						|
////////////////////////
 | 
						|
 | 
						|
class TPrice_recordset : public TISAM_recordset
 | 
						|
{
 | 
						|
  int _mode;
 | 
						|
  bool _roundup;
 | 
						|
  int _decimals;
 | 
						|
  real _perc, _incmin;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual const TVariant& get_field(int logic, const char* field) const;
 | 
						|
 | 
						|
public:
 | 
						|
  TPrice_recordset(const TMask& m);
 | 
						|
};
 | 
						|
 | 
						|
const TVariant& TPrice_recordset::get_field(int logic, const char* field) const
 | 
						|
{
 | 
						|
  if ((logic == 0 || logic == LF_LVRCONDV) && strncmp(field, "NEW", 3) == 0)
 | 
						|
  {
 | 
						|
    const TFixed_string base(field+3);
 | 
						|
    if (((_mode & 1) && (base == LVRCONDV_PREZZO)) || ((_mode & 2) && (base == LVRCONDV_PREZNOL)))
 | 
						|
    {
 | 
						|
      const real old_price = TISAM_recordset::get_field(logic, base).as_real();
 | 
						|
      if (old_price > ZERO)
 | 
						|
      {
 | 
						|
        real new_price = old_price * (CENTO + _perc) / CENTO;
 | 
						|
        if (_roundup)
 | 
						|
          new_price.ceil(_decimals);
 | 
						|
        else
 | 
						|
          new_price.round(_decimals);
 | 
						|
        if (new_price == old_price && _perc > ZERO)
 | 
						|
          new_price += _incmin;
 | 
						|
        TVariant& tmp = get_tmp_var();
 | 
						|
        tmp.set(new_price);
 | 
						|
        return tmp;
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return TISAM_recordset::get_field(logic, field);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TPrice_recordset::TPrice_recordset(const TMask& m) : TISAM_recordset("USE LVRCONDV")
 | 
						|
{
 | 
						|
  _mode = m.get_int(F_PREZZO);
 | 
						|
  _decimals = m.get_int(F_DECIMALS);
 | 
						|
  _roundup = m.get_bool(F_ARROTONDA);
 | 
						|
  _perc = m.get_real(F_PERC);
 | 
						|
  _incmin = m.get_real(F_MINIMO);
 | 
						|
 | 
						|
  const TString4 nil = "???";
 | 
						|
  const TString& por = m.get_bool(F_USEPORTO)  ? m.get(F_PORTO)  : nil;
 | 
						|
  const TString& cco = m.get_bool(F_USECATCON) ? m.get(F_CATCON) : nil;
 | 
						|
  const TString& cve = m.get_bool(F_USECATVEN) ? m.get(F_CATVEN) : nil;
 | 
						|
  const bool cfven_needed = por != nil || cco != nil || cve != nil;
 | 
						|
 | 
						|
  TString select;
 | 
						|
  if (cfven_needed)
 | 
						|
  {
 | 
						|
    if (por != nil) select << "&&(CFVEN.CODPORTO==\""<< por << "\")";
 | 
						|
    if (cco != nil) select << "&&(CFVEN.CODCATC==\"" << cco << "\")";
 | 
						|
    if (cve != nil) select << "&&(CFVEN.CATVEN==\""  << cve << "\")";
 | 
						|
  }
 | 
						|
 | 
						|
  const TString& dca = m.get(F_FROMCODART);
 | 
						|
  const TString& aca = m.get(F_TOCODART);
 | 
						|
  if (dca.full() || aca.full())
 | 
						|
    select << "&&(BETWEEN(CODART,\"" << dca << "\",\"" << aca << "\"))";
 | 
						|
 | 
						|
  TString query;
 | 
						|
  query << "USE LVRCONDV SELECT (BETWEEN(\""<< m.get(F_DATA) << "\",LVCONDV.DATAIN,LVCONDV.DATASC))";
 | 
						|
  switch (_mode)
 | 
						|
  {
 | 
						|
  case  1: query << "&&(STR(PREZZO>0))"; break;
 | 
						|
  case  2: query << "&&(STR(PREZNOL>0))"; break;
 | 
						|
  default: query << "&&(STR((PREZZO>0)||(PREZNOL>0)))"; break;
 | 
						|
  }
 | 
						|
  query << select;
 | 
						|
  query << "\nJOIN LVCONDV INTO CODCF==CODCF CODCONT==CODCONT";
 | 
						|
  if (cfven_needed)
 | 
						|
    query << "\nJOIN CFVEN INTO TIPOCF=\"C\" CODCF==CODCF";
 | 
						|
  query << "\nFROM CODCF=" << m.get(F_FROMCLI) << "\nTO CODCF=" << m.get(F_TOCLI);
 | 
						|
 | 
						|
  set(query);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
////////////////////
 | 
						|
//  Applicazione  //
 | 
						|
////////////////////
 | 
						|
 | 
						|
class TAggiornamento_prezzi : public TSkeleton_application
 | 
						|
{ 
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
void TAggiornamento_prezzi::main_loop()
 | 
						|
{
 | 
						|
  TPrezzi_mask m;
 | 
						|
  while (m.run() == K_ENTER)
 | 
						|
  {
 | 
						|
    TPrice_recordset* pr = new TPrice_recordset(m);
 | 
						|
    TReport rep; 
 | 
						|
    if (rep.load("lv4900"))
 | 
						|
    {
 | 
						|
      rep.set_recordset(pr);
 | 
						|
      rep.preview();
 | 
						|
    }
 | 
						|
 | 
						|
    if (m.get_bool(F_DEFINITIVO) && yesno_box(TR("Si desiderano registrare i nuovi prezzi?")))
 | 
						|
    {
 | 
						|
      const int mode = m.get_int(F_PREZZO); // 1, 2, 3
 | 
						|
      TProgind pi(pr->items(), title(), false, true);
 | 
						|
      const TRectype& curr = pr->cursor()->curr();
 | 
						|
      TFast_isamfile file(LF_LVRCONDV);
 | 
						|
      for (bool ok = pr->move_first(); ok; ok = pr->move_next())
 | 
						|
      {
 | 
						|
        if (!pi.addstatus(1)) 
 | 
						|
          break;
 | 
						|
        file.curr() = curr;
 | 
						|
        if (mode & 1)
 | 
						|
          file.put(LVRCONDV_PREZZO, pr->get("NEW"LVRCONDV_PREZZO).as_real());
 | 
						|
        if (mode & 2)
 | 
						|
          file.put(LVRCONDV_PREZNOL, pr->get("NEW"LVRCONDV_PREZNOL).as_real());
 | 
						|
        const int err = file.rewrite();
 | 
						|
        if (err != NOERR)
 | 
						|
        {
 | 
						|
          cantwrite_box(file.description());
 | 
						|
          break;
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int lv4900(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TAggiornamento_prezzi a;
 | 
						|
  a.run(argc, argv, TR("Aggiornamento prezzi"));
 | 
						|
  return 0;
 | 
						|
}
 |