bool SDOMerData::SpInvoices() { // podle invoice overview ze sage ASGInvoiceData sgInv; ASGSop sgSop; AxDynaset ds; if( ds.Open( "select sgmskeya,sgmskeyb,sgmsinvd,sgmssop,sgmscname,sgmsdaddr1,sgmssettr,sgmssett,sgmscarr,sgmsaccref,sgmsneta from sgmersp where 0=1", ADYNASET_NC_NB, true) != ASUCCESS) { return false; } short nInvType; // typ faktury DATE dtInv; // datum faktury short nPosted,nStatus; // odeslano do ucetnictvi, stav SOP long nSop; // SOP jako long double dNetAmount; // cena za polozky nez dane double dSettDiscRate; // sleva v % double dSettDisc; // sleva v castce double dCarriage; // dopravne char sSop[16], sInv[16], sRef[16]; char sDelAdr1[61], sCustName[61]; long iImportedRows = 0; // naimportovanych radku AxisBatch.Printf( "Importing data fom Sage..."); AxisBatch.Clear(sgInv.GetRecordCount()); for( sgInv.MoveFirst(); !sgInv.IsEOF(); sgInv.MoveNext()) { AxisBatch.Event(); if (AxisBatch.IsCanceled()) { return false; } sgInv.GetFieldValue( "INVOICE_NUMBER", sInv, sizeof sInv); sgInv.GetFieldValue("INVOICE_TYPE_CODE", nInvType); if(nInvType!=sdoProductProforma && nInvType!=sdoServiceProforma) { sgInv.GetFieldValue("POSTED_CODE", nPosted); if( nPosted == 1) { sgInv.GetFieldValue("INVOICE_DATE", dtInv); if( m_dtSpMin<=dtInv && dtInv<=m_dtSpMax) { sgInv.GetFieldValue("ORDER_NUMBER", sSop, sizeof sSop); if( *sSop && strlen( sSop)<8 && sgSop.Find( nSop=atol( sSop))) { sgSop.GetFieldValue("STATUS", nStatus); if(nStatus != sdoCancelled && nStatus != sdoPartCancelled) { sgSop.GetFieldValue("ACCOUNT_REF", sRef, sizeof sRef); if (strcmp(sRef, "STOCK") && strcmp(sRef, "BARRYF") && strcmp(sRef, "CLAIMACC")) { sgSop.GetFieldValue( "SETTLEMENT_DISC_RATE", dSettDiscRate); sgSop.GetFieldValue( "ITEMS_NET", dNetAmount); dSettDisc = dNetAmount * (dSettDiscRate/100.0); if( dSettDisc) { sgSop.GetFieldValue( "NAME", sCustName, sizeof sCustName); sgSop.GetFieldValue( "DEL_ADDRESS_1", sDelAdr1, sizeof sDelAdr1); sgSop.GetFieldValue( "CARR_NET", dCarriage); if( ds.AddNewRecord() == ASUCCESS) { ds.SetFieldValue(0, m_user); // Axis user ds.SetFieldValue(1, sInv); // Invoice ds.SetFieldValue(2, dtInv); // Invoice date ds.SetFieldValue(3, sSop); // Order ds.SetFieldValue(4, sCustName); // Customer name ds.SetFieldValue(5, sDelAdr1); // Delivery addess 1 ds.SetFieldValue(6, dSettDiscRate); // Settlement rate ds.SetFieldValue(7, dSettDisc); // Settlement ds.SetFieldValue(8, dCarriage); // Carriage NET amount ds.SetFieldValue(9, sRef); // Account reference ds.SetFieldValue(10,dNetAmount); // Invoice NET amount if( ds.Update() == ASUCCESS) iImportedRows++; else AxisBatch.Printf( " Import error: %s", ds.GetErrorText()); } } } } } } } } } AxisBatch.Printf( "... %d records imported.", iImportedRows); return true; }