diff --git a/ha/ha1300.cpp b/ha/ha1300.cpp index de037f0ea..a2b65f56b 100755 --- a/ha/ha1300.cpp +++ b/ha/ha1300.cpp @@ -531,7 +531,10 @@ void TUpload2Campo::elabora_VC(THardy_upload_recordset& recset, TLog_report& log file_cfven.zero(); file_cfven.put(CFV_TIPOCF, 'C'); file_cfven.put(CFV_CODCF, codcf); - err = file_cfven.write(); + if (_can_write) + err = file_cfven.write(); + else + err = NOERR; } //se la creazione non va a buon fine avverte if (err != NOERR) @@ -546,18 +549,17 @@ void TUpload2Campo::elabora_VC(THardy_upload_recordset& recset, TLog_report& log const TString& codlist = recset.get("CodiceListino").as_string(); file_cfven.put(CFV_CODLIST, codlist); - //se alla fin fine può scrivere -> aggiorna sia clifo che cfven - if (_can_write) - file_clifo.rewrite(); - //incredibilmente arriva in fondo + //incredibilmente arriva in fondo TString msg; msg << "Cliente: " << codcf << " Terminale: " << codice_terminale; //se può scrivere... if (_can_write) { //alla fine della fiera salva il cliente e il cfven - err = file_clifo.rewrite() && file_cfven.rewrite(); + err = file_clifo.rewrite(); + if (err == NOERR) + err = file_cfven.rewrite(); if (err == NOERR) { @@ -577,18 +579,18 @@ void TUpload2Campo::elabora_SI(THardy_upload_recordset& recset, TLog_report& log { //dati dal recordset di upload (con i relativi controlli) TString4 codice_terminale = recset.get("CodiceTerminale").as_string(); - const TString& codice_agente = check_agente(codice_terminale, log); + const TString8 codice_agente = check_agente(codice_terminale, log); const TString& str_codcf = recset.get("CodiceCliente").as_string(); long codcf = check_cliente(str_codcf, log); //crea un movimento contabile pescando i dati dal recordset (e inventandosene qualcuno!) //testata - const char tipo_cf = 'C'; const TDate data_incasso = recset.get("DataIncasso").as_date(); const TDate datareg = data_incasso; const TDate datacomp = data_incasso; TEsercizi_contabili esc; const int annoes = esc.date2esc(data_incasso); + const int anno = datareg.year(); const long numdoc = recset.get("NumeroFattura").as_int(); const TDate datadoc = recset.get("DataFattura").as_date(); const TString4 tipodoc = recset.get("TipoDocumento").as_string(); @@ -596,9 +598,7 @@ void TUpload2Campo::elabora_SI(THardy_upload_recordset& recset, TLog_report& log TConfig config(CONFIG_DITTA, "ha"); const TString& codcaus = config.get("InpCausale"); - const TCausale caus(codcaus, datareg.year()); - const int riga_abb = RIGA_ABBUONI_PASSIVI; - TBill conto_abbuoni; caus.bill(riga_abb, conto_abbuoni); + const TCausale caus(codcaus, anno); TMovimentoPN mov; TRectype& head = mov.curr(); @@ -613,22 +613,93 @@ void TUpload2Campo::elabora_SI(THardy_upload_recordset& recset, TLog_report& log head.put(MOV_DATADOC, datadoc); head.put(MOV_NUMDOC, numdoc); head.put(MOV_TIPODOC, tipodoc); + head.put(MOV_TIPOMOV, caus.tipomov()); + head.put(MOV_ANNOIVA, anno); + head.put(MOV_TOTDOC, incasso); + + long numreg = 999999L; if (_can_write) { - if (mov.write() != NOERR) - _can_write = false; TString msg; - msg << "Movimento di incasso non registrato. Cliente: " << codcf << " - Agente: " << codice_agente << " - Data: " << data_incasso; - log.log(2, msg); + msg << " movimento di incasso. Cliente: " << codcf << " - Agente: " << codice_agente << " - Data: " << data_incasso; + if (mov.write() != NOERR) + { + _can_write = false; + msg.insert("Impossibile registrare"); + log.log(2, msg); + } + else + { + msg.insert("Registrato"); + log.log(0, msg); + numreg = head.get_long(MOV_NUMREG); + } } - const long numreg = head.get_long(MOV_NUMREG); + //righe + //panegirico sui conti + //conto cliente + TToken_string key_clifo; + key_clifo.add('C'); + key_clifo.add(codcf); + const TRectype& rec_codcf = cache().get(LF_CLIFO, key_clifo); + int gr_cli = rec_codcf.get_int(CLI_GRUPPO); + int co_cli = rec_codcf.get_int(CLI_CONTO); + TBill zio_clifo(gr_cli, co_cli, codcf ,'C'); + //se il cliente non ha un suo conto, prova con il primo della causale incassi in configurazione + if (zio_clifo.conto() <= 0) + { + caus.bill(0, zio_clifo); + gr_cli = zio_clifo.gruppo(); + co_cli = zio_clifo.conto(); + zio_clifo.set(gr_cli, co_cli, codcf, 'C'); + } + //conto agente + const TRectype& rec_agente = cache().get(LF_AGENTI, codice_agente); + int gr_age = rec_agente.get_int(AGE_GRUPPO); + int co_age = rec_agente.get_int(AGE_CONTO); + long sott_age = rec_agente.get_long(AGE_SOTTOCONTO); + TBill zio_agente(gr_age, co_age, sott_age); + //se l'agente non ha un suo conto, prova con il secondo della causale incassi in configurazione + if (zio_agente.conto() <= 0) + { + caus.bill(1, zio_agente); + gr_age = zio_agente.gruppo(); + co_age = zio_agente.conto(); + sott_age = zio_agente.sottoconto(); + zio_agente.set(gr_age, co_age, sott_age); + } + //creazione vera e propria delle righe + //riga 1: conto cliente + TRectype& new_rmov_cli = mov.cg(-1); + new_rmov_cli.put(RMV_ROWTYPE, 'K'); + zio_clifo.put(new_rmov_cli); + const char sezione_cli = caus.sezione(0); + new_rmov_cli.put(RMV_SEZIONE, sezione_cli); + TString descr_rmv_cli; + descr_rmv_cli << "Incasso cliente " << codcf; + new_rmov_cli.put(RMV_DESCR, descr_rmv_cli); + zio_agente.put(new_rmov_cli, true); //conto di contropartita = conto agente + new_rmov_cli.put(RMV_IMPORTO, incasso); + //riga 2: conto agente + TRectype& new_rmov_age = mov.cg(-1); + new_rmov_age.put(RMV_ROWTYPE, 'I'); + zio_agente.put(new_rmov_age); + const char sezione_age = caus.sezione(1); + new_rmov_age.put(RMV_SEZIONE, sezione_age); + TString descr_rmv_age; + descr_rmv_age << "Incasso agente " << codice_agente; + new_rmov_age.put(RMV_DESCR, descr_rmv_age); + zio_clifo.put(new_rmov_age, true); //conto di contropartita = conto cliente + new_rmov_age.put(RMV_IMPORTO, incasso); - //crea i pagamenti aggiornando anche la partita + //crea i pagamenti aggiornando anche la partita (qui si parrà la tua nobilitate!) + //alla fine della fiera scrive (se può) movimento e pagamento + } @@ -743,7 +814,7 @@ void TUpload2Campo::elabora_TF(THardy_upload_recordset& recset, TLog_report& log { char rec_tipodoc = recset.get(DOC_TIPODOC).as_string()[0]; //i documenti di vendita annullati vanno ignorati - if (rec_tipodoc == 'A' || rec_tipodoc == 'N') + if (rec_tipodoc == 'A' || rec_tipodoc == 'N' || rec_tipodoc <= ' ') return; //1) codice terminale (lungo 3) e codice agente (lungo 5) @@ -1060,8 +1131,6 @@ void TUpload2Campo::elabora_RC(THardy_upload_recordset& recset, TLog_report& log void TUpload2Campo::elabora(const TMask& mask) { - - //creazione del filename del file da importare TFilename src_file = mask.get(F_PATH); src_file.add(UPLOAD_FILE); @@ -1097,6 +1166,7 @@ void TUpload2Campo::elabora(const TMask& mask) TString4 tipo_record = recset.rec_type(); tipo_record.trim(); + //"SU|VC|TF|RF|SI|BR|RC" const int pos = tipi_record.get_pos(tipo_record); //trattazione dei vari tracciati record @@ -1105,21 +1175,21 @@ void TUpload2Campo::elabora(const TMask& mask) case 0: //tipo record: SU (SetUp...ovvero agente) //elabora_SU(recset, log); //non serve a una cippa! break; - case 1: //tipo record: TF (Testata Fattura) + case 1: //tipo record: VC (nuovi clienti e Variazioni Cliente) + elabora_VC(recset, log); + break; + case 2: //tipo record: TF (Testata Fattura) elabora_TF(recset, log); break; - case 2: //tipo record: RF (Riga Fattura) + case 3: //tipo record: RF (Riga Fattura) //elabora_RF(recset, log); //non serve! lo fa l'elaborazione di testata break; - case 3: //tipo record: SI (incasso documenti) - elabora_SI(recset, log); + case 4: //tipo record: SI (incasso documenti) + //elabora_SI(recset, log); break; - case 4: //tipo record: BR (righe movimenti magazzino) + case 5: //tipo record: BR (righe movimenti magazzino) elabora_BR(recset, log); break; - case 5: //tipo record: VC (nuovi clienti e Variazioni Cliente) - elabora_VC(recset, log); - break; case 6: //tipo record: RC (Richiesta Carico) elabora_RC(recset, log); break;