Aqui va algo del codigo
Código Delphi
[-]
procedure TFFACTURACION.BitBtn3Click(Sender: TObject);
Begin
Try
If MessageDlg('¿Está seguro(a) que desea FACTURAR el PERIODO'+IntToStr(intMesPer)+'-'+IntToStr(intAnoPer)+'?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
Begin
DM.BD.BeginTrans;
strPerFac:=CerosIzquierda(intMesPer,2)+'-'+IntTostr(intAnoPer);
intTcbFac:=DM.GetTcbFac;
If DM.GetDosifica(1,intNroAut,intNroRen,strFecLim,strKeyDos) Then
If FacturarEmpresa Then
Begin
ShowMessage('¡El PROCESO DE FACTURACIÓN FINALIZÓ CORRECTAMENTE!.');
DM.BD.CommitTrans;
End
Else
Begin
ShowMessage('¡El PROCESO DE FACTURACIÓN FALLÓ!.');
DM.BD.RollbackTrans;
End;
End;
Except on E:Exception do
Begin
DM.BD.RollbackTrans;
ShowMessage(E.Message);
End;
End;
End;
Ese es el procedimiento del boton que realiza el proceso
function TFFACTURACION.FacturarEmpresa: Boolean;
Var strSQL,strNroFac:String;
intTotFac,intTotIva:Real;
i:Integer;
begin
Try
With QCONTRATOS do
Begin
ObtenerParametros(1,1,1);
strSQL:='SELECT *,S.NROSER FROM SIIELE.LECTURAS ,SIIELE.CTOGRL C, SIIELE.CTOSER S ';
strSQL:=strSQL+'WHERE C.NROCTO=S.NROCTO AND L.NROCTO=C.NROCTO AND L.NROFAC IS NULL AND ';
strSQL:=strSQL+'L.MESPER='+IntToStr(intMesPer)+' AND L.ANOPER='+IntToStr(intAnoPer);
strSQL:=strSQL+' ORDER BY C.NROCTO';
SQL.Clear;
SQL.Add(strSQL);
Open;
First;
While Not EOF do
Begin
intPosVec:=0;i:=1;
While intPosVec=0 do
Begin
If vecParFac[i].NomPla=QCONTRATOS.FieldByName('CODPLA').AsString Then
intPosVec:=i
Else
i:=i+1;
End;
strNroFac:=CerosIzquierda(intMesPer,2)+IntToStr(intAnoPer)+CerosIzquierda(intNroAct,4);
intTotFac:=0;intTotIva:=0;
If FacturarServicio(QCONTRATOS,strNroFac,intTotFac,intTotIva) Then
If FacturarLeyes(QCONTRATOS,strNroFac,intTotFac,intTotIva) Then
If FacturarCreditos(QCONTRATOS,strNroFac,intTotFac,intTotIva) Then
If FacturarIndefinidos(QCONTRATOS,strNroFac,intTotFac,intTotIva) Then
If InsertarFactura(QCONTRATOS,strNroFac,intTotFac,intTotIva) Then
Begin
ActualizarLectura(QCONTRATOS,strNroFac);
intNroAct:=intNroAct+1;
intNroRen:=intNroRen+1;
Next;
End
Else
Begin
Result:=False;
Exit;
End
Else
Begin
Result:=False;
Exit;
End
Else
Begin
Result:=False;
Exit;
End
Else
Begin
Result:=False;
Exit;
End
Else
Begin
Result:=False;
Exit;
End;
End;
End;
Result:=True;
Except on E:Exception do
Begin
Result:=False;
ShowMessage(E.Message);
End;
End;
end;
ESE ES EL PROCESO QUE REALIZA TODA LA FACTURACION
function TFFACTURACION.FacturarServicio(Q:TADOQuery;strNroFac:String;Var intTotFac,intTotIVA:Real): Boolean;
Var
intTotCon,intCanMin,intCanDem:Integer;
intPreMin,intPreKws,intPreDem:Real;
begin
Try
intCanMin:=0;intPreKws:=0;
If vecParFac[intPosVec].CanMin>0 Then
Begin
intCanMin:=vecParFac[intPosVec].CanMin;
intPreMin:=vecParFac[intPosVec].PreMin;
InsertarDetalle(strNroFac,'MINENE',Q.FieldByName('CODEMP').AsInteger,
Q.FieldByName('CODSER').AsInteger,intPreMin,1,intTotFac,intTotIVA);
End;
If Q.FieldByName('CONLEC').AsInteger>intCanMin Then
Begin
intTotCon:=Q.FieldByName('CONLEC').AsInteger-intCanMin;
intPreKws:=vecParFac[intPosVec].PreKws;
InsertarDetalle(strNroFac,'KWSENE',Q.FieldByName('CODEMP').AsInteger,
Q.FieldByName('CODSER').AsInteger,intPreKws,intTotCon,intTotFac,intTotIVA);
End;
If Q.FieldByName('DEMLEC').AsInteger>0 Then
Begin
intCanDem:=Q.FieldByName('DEMLEC').AsInteger;
intPreDem:=vecParFac[intPosVec].PreDem;
InsertarDetalle(strNroFac,'DEMENE',Q.FieldByName('CODEMP').AsInteger,
Q.FieldByName('CODSER').AsInteger,intPreDem,intCanDem,intTotFac,intTotIVA);
End;
If Q.FieldByName('MULLEC').AsInteger>0 Then
Begin
intTotCon:=Q.FieldByName('MULLEC').AsInteger;
InsertarDetalle(strNroFac,'BFPDIG',Q.FieldByName('CODEMP').AsInteger,
Q.FieldByName('CODSER').AsInteger,intPreKws,intTotCon,intTotFac,intTotIVA);
End;
Result:=True;
Except on E:Exception do
Begin
Result:=False;
ShowMessage(E.Message+'SERVICIO'+Q.FIeldByName('NROCTO').AsString);
End;
End;
end;
ESTE FACTURA EL SERVICIO
function TFFACTURACION.FacturarLeyes(Q:TADOQuery;strNroFac:String;Var intTotFac,intTotIVA:Real): Boolean;
Var
intTotBen,intMtoLey,intPreMin,intPreKws,intPreDem:Real;
intTotCon,intCanMin,intCanLey,intValLey,i,intCanDem:Integer;
Aplica:Boolean;
begin
Try
intTotBen:=0;
intTotCon:=Q.FieldByName('TOTCON').AsInteger;
For i:=1 to vecParFac[intPosVec].CanLeyes do
Begin
intCanMin:=0;intCanDem:=0;
intPreMin:=0;intPreKws:=0;intPreDem:=0;
Aplica:=False;
If (vecParFac[intPosVec].vecLeyes[i].NomLey='LEY1886') and
(EsLey1886(Q.FieldByName('NROCTO').AsString)) Then
Aplica:=True
Else
If (vecParFac[intPosVec].vecLeyes[i].NomLey='TARDIG')and
(intTotCon<=DM.TLEYES.FieldByName('APLCAN').AsInteger) Then
Aplica:=True
Else
If vecParFac[intPosVec].vecLeyes[i].NomLey='ALUPUB' Then
Aplica:=True;
If Aplica Then
Begin
intCanLey:=vecParFac[intPosVec].vecLeyes[i].CanLey;
intValLey:=vecParFac[intPosVec].vecLeyes[i].ValLey;
If vecParFac[intPosVec].vecLeyes[i].AplMin='S' Then
Begin
intCanMin:=vecParFac[intPosVec].CanMin;
intPreMin:=vecParFac[intPosVec].PreKws;
End;
If vecParFac[intPosVec].vecLeyes[i].AplCon='S' Then
Begin
intCanDem:=Q.FieldByName('DEMLEC').AsInteger;
intPreKws:=vecParFac[intPosVec].PreKws;
intPreDem:=vecParFac[intPosVec].PreDem;
End;
If vecParFac[intPosVec].vecLeyes[i].ConLey='HASTA' Then
Begin
If intTotCon>intCanLey Then
intMtoLey:=(intPreMin*intValLey/100)+((intCanLey-intCanMin)*intPreKws*intValLey/100)
Else
intMtoLey:=(intPreMin*intValLey/100)+((intTotCon-intCanMin)*intPreKws*intValLey/100);
End
Else If intTotCon>intCanMin Then
intMtoLey:=(intPreMin*intValLey/100)+((intTotCon-intCanMin)*intPreKws*intValLey/100)+((intCanDem*intPreDem)*intValLey/100)
Else
intMtoLey:=(intPreMin*intValLey/100)+((intCanDem*intPreDem)*intValLey/100);
If vecParFac[intPosVec].vecLeyes[i].EsBene='S' Then
intTotBen:=intTotBen+intMtoLey;
If vecParFac[intPosVec].vecLeyes[i].AplBen='S' Then
intMtoLey:=intMtoLey-(intTotBen*intValley/100);
If vecParFac[intPosVec].vecLeyes[i].TipCob='DEB' Then
intMtoLey:=intMtoLey*(-1);
InsertarDetalle(strNroFac,vecParFac[intPosVec].vecLeyes[i].CodItm,Q.FieldByName('CODEMP').AsInteger,
Q.FieldByName('CODSER').AsInteger,intMtoLey,1,intTotFac,intTotIva);
End;
End;
Result:=True;
Except on E:Exception do
Begin
Result:=False;
ShowMessage(E.Message+'LEYES'+DM.TLEYES.FieldByName('NROCTO').AsString);
End;
End;
end;
ESE FACTURA LAS LEYES
BASICAMENTE ESE ES EL CODIGO DE LOS DOS PROCESOS MENCIONADOS ANTERIORMENTE, SI ALGUIEN TUVIERA UNA OBSERVACION AGRADECERIA QUE ME LA HICIERAN SABER