-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCfaccli.prg
More file actions
5489 lines (4234 loc) · 188 KB
/
Cfaccli.prg
File metadata and controls
5489 lines (4234 loc) · 188 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "FiveWin.Ch"
#include "Factu.ch"
/*
Realiza asientos en Contaplus, partiendo de la factura
*/
//---------------------------------------------------------------------------//
Static Function isIVARegimenGeneralVentas( dbfFactura )
Return ( ( dbfFactura )->nRegIva <= 1 )
//---------------------------------------------------------------------------//
Static Function isIVARegimenGeneralCompras( dbfFactura )
Return ( ( dbfFactura )->nRegIva <= 1 .or. ( dbfFactura )->nRegIva == 4 )
//---------------------------------------------------------------------------//
Static Function isIVAComunidadEconomicaEuropea( dbfFactura )
Return ( ( dbfFactura )->nRegIva == 2 )
//---------------------------------------------------------------------------//
Static Function isIVAExportacionFueraUE( dbfFactura )
Return ( ( dbfFactura )->nRegIva == 4 )
//---------------------------------------------------------------------------//
FUNCTION CntFacCli( lSimula, lPago, lExcCnt, lMessage, oTree, nAsiento, aSimula, dbfFacCliT, dbfFacCliL, dbfFacCliP, dbfAntCliT, dbfCli, dbfDiv, dbfArt, dbfFPago, dbfIva, oNewImp, oBrw, cCodEmp, cCodPro )
local n
local nIva
local cCtaVent
local nPos
local dFecha
local cConcepto
local cPago
local cSubCtaIva
local cSubCtaReq
local cSubCtaIvm
local cSubCtaTrn
local nImpDet
local nImpTrn
local nImpPnt
local nImpIvm
local nImpIva
local cRuta
local nDouDiv
local nRouDiv
local nDpvDiv
local aTotAnt
local nNetAnt
local nIvaAnt
local nAcuAnt := 0
local nTotAnt := 0
local uIva
local newIva
local aIvm := {}
local aTrn := {}
local aAsiento := {}
local nCalculo := 0
local nBase := 0
local aVentas := {}
local lIvaInc := ( dbfFacCliT )->lIvaInc
local cCodDiv := ( dbfFacCliT )->cDivFac
local cCtaCli := cCliCta( ( dbfFacCliT )->cCodCli, dbfCli )
local cCtaCliVta := cCliCtaVta( ( dbfFacCliT )->cCodCli, dbfCli )
local cCtaAnticipo := cCtaAnt()
local nFactura := ( dbfFacCliT )->cSerie + str( ( dbfFacCliT )->nNumFac ) + ( dbfFacCliT )->cSufFac
local cFactura := ( dbfFacCliT )->cSerie + alltrim( str( ( dbfFacCliT )->nNumFac ) )
local pFactura := ( dbfFacCliT )->cSerie + "/" + alltrim( str( ( dbfFacCliT )->nNumFac ) ) + "/" + ( dbfFacCliT )->cSufFac
local lRecargo := ( dbfFacCliT )->lRecargo
local cTerNif := ( dbfFacCliT )->cDniCli
local cTerNom := ( dbfFacCliT )->cNomCli
local lErrorFound := .f.
local cProyecto
local cClave
local sTotFacCli
local ptaDebe
local ptaRet
local lReturn := .t.
local lOpenDiario := lOpenDiario()
local nTotDebe := 0
local nTotHaber := 0
local nDtoEsp := 0
local nDpp := 0
local nDtoUno := 0
local nDtoDos := 0
local nPctDto := 0
local nPctIva := 0
local nBaseImp := 0
local aAsientoSII
local aAsientosSII := {}
DEFAULT lSimula := .t.
DEFAULT nAsiento := 0
DEFAULT aSimula := {}
DEFAULT cCodEmp := cCodEmpCnt( ( dbfFacCliT )->cSerie )
DEFAULT cCodPro := ( dbfFacCliT )->cCodPro
nDouDiv := nDouDiv( ( dbfFacCliT )->cDivFac, dbfDiv )
nRouDiv := nRouDiv( ( dbfFacCliT )->cDivFac, dbfDiv )
nDpvDiv := nDpvDiv( ( dbfFacCliT )->cDivFac, dbfDiv )
dFecha := ( dbfFacCliT )->dFecFac
nDtoEsp := ( dbfFacCliT )->nDtoEsp
nDpp := ( dbfFacCliT )->nDpp
nDtoUno := ( dbfFacCliT )->nDtoUno
nDtoDos := ( dbfFacCliT )->nDtoDos
nPctDto := ( dbfFacCliT )->nPctDto
sTotFacCli := sTotFacCli( ( dbfFacCliT )->cSerie + str( ( dbfFacCliT )->nNumFac ) + ( dbfFacCliT )->cSufFac, dbfFacCliT, dbfFacCliL, dbfIva, dbfDiv, dbfFacCliP, dbfAntCliT, nil, nil, .f., lExcCnt )
ptaDebe := sTotFacCli:nTotalDocumento
ptaRet := sTotFacCli:nTotalRetencion
newIva := sTotFacCli:aTotalIva
cProyecto := Left( cCodPro, 3 )
cClave := Right( cCodPro, 6 )
/*
Seleccionamos las empresa dependiendo de la serie de factura----------------
*/
cRuta := cRutCnt()
if !chkEmpresaAsociada( cCodEmp )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " no se definierón empresas asociadas.", 0 ) )
lErrorFound := .t.
end if
if !ChkRuta( cRutCnt() )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " ruta no valida.", 0 ) )
lErrorFound := .t.
end if
if !ChkFecha( cRuta, cCodEmp, ( dbfFacCliT )->dFecFac, .f., oTree, "Factura cliente : " + rtrim( pFactura ) )
lErrorFound := .t.
end if
/*
Preparamos los apuntes de cliente-------------------------------------------
*/
if Empty( cCtaCli )
cCtaCli := cCtaSin()
end if
if Empty( cCtaCliVta )
cCtaCliVta := cCtaCli()
end if
/*
Estudio de los Articulos de una factura-------------------------------------
*/
if ( dbfFacCliL )->( dbSeek( nFactura ) )
while ( ( dbfFacCliL )->cSerie + str( ( dbfFacCliL )->nNumFac ) + ( dbfFacCliL )->cSufFac == nFactura .and. !( dbfFacCliL )->( eof() ) )
if !( dbfFacCliL )->lTotLin .and. ;
lValLine( dbfFacCliL ) // .and. ;
// nTotLFacCli( dbfFacCliL, nDouDiv, nRouDiv, nil, .t., .t., .t. ) != 0
if ( lExcCnt == nil .or.; // Entran todos
( lExcCnt .and. ( dbfFacCliL )->nCtlStk != 2 ) .or.; // Articulos sin contadores
( !lExcCnt .and. ( dbfFacCliL )->nCtlStk == 2 ) ) // Articulos con contadores
nIva := ( dbfFacCliL )->nIva
nImpDet := nTotLFacCli( dbfFacCliL, nDouDiv, nRouDiv, nil, .t., .f., .f. )
nImpTrn := nTrnLFacCli( dbfFacCliL, nDouDiv, nRouDiv ) // Portes
/*
Si en la factura nos piden q operemeos con punto verde----------
*/
if ( dbfFacCliT )->lOperPV
nImpPnt := nPntLFacCli( dbfFacCliL, nDpvDiv )
else
nImpPnt := 0
end if
nImpIva := nIvaLFacCli( dbfFacCliL, nDouDiv, nRouDiv )
nImpIvm := nTotIFacCli( dbfFacCliL, nDouDiv, nRouDiv )
/*
Cuenta de venta si es una devolucion----------------------------
*/
cCtaVent := RetCtaVta( ( dbfFacCliL )->cRef, ( nImpDet < 0 ), dbfArt )
if empty( cCtaVent )
cCtaVent := cCtaCliVta + RetGrpVta( ( dbfFacCliL )->cRef, cRuta, cCodEmp, nIva )
end if
/*
Cuentas de ventas--------------------------------------------------
*/
nPos := aScan( aVentas, {|x| x[ 1 ] == cCtaVent .and. x[ 2 ] == nIva } )
if nPos == 0
aAdd( aVentas, { cCtaVent, nIva, nImpDet, nImpPnt, nImpTrn, nImpIva, .t. } )
else
aVentas[ nPos, 3 ] += nImpDet
aVentas[ nPos, 4 ] += nImpPnt
aVentas[ nPos, 5 ] += nImpTrn
aVentas[ nPos, 6 ] += nImpIva
end if
/*
Construimos las bases de los impuestos-----------------------------
*/
if isIVAComunidadEconomicaEuropea( dbfFacCliT )
cSubCtaIva := uFieldEmpresa( "cCtaCeeRpt" )
cSubCtaReq := uFieldEmpresa( "cCtaCeeSpt" )
else
cSubCtaIva := cSubCuentaIva( nIva, ( dbfFacCliT )->lRecargo, cRuta, cCodEmp, dbfIva )
cSubCtaReq := cSubCuentaRecargo( nIva, ( dbfFacCliT )->lRecargo, cRuta, cCodEmp, dbfIva )
end if
if uFieldEmpresa( "lIvaImpEsp" )
nImpDet += nImpIvm
end if
/*
transportes--------------------------------------------------------
*/
if nImpTrn != 0
cSubCtaTrn := RetCtaTrn( ( dbfFacCliL )->cRef, dbfArt )
nPos := aScan( aTrn, {|x| x[1] == cSubCtaTrn } )
if nPos == 0
aAdd( aTrn, { cSubCtaTrn, nImpTrn } )
else
aTrn[ nPos, 2 ] += nImpTrn
end if
end if
/*
impuesto especiales---------------------------------------------------
*/
nImpIvm := nTotIFacCli( dbfFacCliL, nDouDiv, nRouDiv )
if nImpIvm != 0
cSubCtaIvm := oNewImp:cCtaImp( oNewImp:nValImp( ( dbfFacCliL )->cCodImp ) )
if !Empty( cSubCtaIvm )
nPos := aScan( aIvm, {|x| x[1] == cSubCtaIvm } )
if nPos == 0
aAdd( aIvm, { cSubCtaIvm, nImpIvm } )
else
aIvm[ nPos, 2 ] += nImpIvm
end if
end if
end if
end if
end if
SysRefresh()
( dbfFacCliL )->( dbSkip() )
end while
else
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " factura sin artículos.", 0 ) )
lErrorFound := .t.
end if
/*
Descuentos sobres grupos de Venta
--------------------------------------------------------------------------
*/
for n := 1 to Len( aVentas )
nRestaDescuentoVenta( @aVentas[ n, 3 ], nDtoEsp )
nRestaDescuentoVenta( @aVentas[ n, 3 ], nDpp )
nRestaDescuentoVenta( @aVentas[ n, 3 ], nDtoUno )
nRestaDescuentoVenta( @aVentas[ n, 3 ], nDtoDos )
nRestaDescuentoVenta( @aVentas[ n, 3 ], nPctDto )
next
/*
Gastos se lo sumamos a la base----------------------------------------------
*/
if ( ( dbfFacCliT )->nManObr != 0 )
cSubCtaTrn := uFieldEmpresa( "cCtaGas")
nPos := aScan( aVentas, {|x| x[ 1 ] == cSubCtaTrn .and. x[ 2 ] == ( dbfFacCliT )->nIvaMan } )
if nPos == 0
aAdd( aVentas, { cSubCtaTrn, ( dbfFacCliT )->nIvaMan, ( dbfFacCliT )->nManObr, 0, 0, 0, .f. } )
else
aVentas[ nPos, 3 ] += ( dbfFacCliT )->nManObr
end if
end if
/*
Despues de aplicar los descuentos le sumamos el punto verde-----------------
*/
for n := 1 to Len( aVentas )
aVentas[ n, 3 ] += aVentas[ n, 4 ]
next
/*
Ponemos la cuentas de IVA---------------------------------------------------
*/
for each uIva in newIva
if isNum( uIva[ 3 ] )
/*
Construimos las bases de los impuestos--------------------------------
*/
if isIVAComunidadEconomicaEuropea( dbfFacCliT )
cSubCtaIva := cCuentaVentaIVARepercutidoUE()
uIva[ 3 ] := 0
aAdd( uIva, cSubCtaIva )
elseif isIVAExportacionFueraUE( dbfFacCliT )
cSubCtaIva := cCuentaVentaIVARepercutidoFueraUE()
uIva[ 3 ] := 0
aAdd( uIva, cSubCtaIva )
else
aAdd( uIva, cSubCuentaIva( uIva[ 3 ], ( dbfFacCliT )->lRecargo, cRuta, cCodEmp, dbfIva ) )
aAdd( uIva, cSubCuentaRecargo( uIva[ 3 ], ( dbfFacCliT )->lRecargo, cRuta, cCodEmp, dbfIva ) )
aAdd( uIva, cSubCuentaIva( uIva[ 3 ], .f., cRuta, cCodEmp, dbfIva ) )
end if
end if
next
/*
Chequando antes de pasar a Contaplus
--------------------------------------------------------------------------
*/
if ( dbfFacCliT )->lContab
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " contabilizada.", 0 ) )
lErrorFound := .t.
end if
if !ChkSubcuenta( cRuta, cCodEmp, cCtaCli, , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " subcuenta " + cCtaCli + " no encontada.", 0 ) )
lErrorFound := .t.
end if
if ptaRet != 0
if !ChkSubcuenta( cRuta, cCodEmp, cCtaRet(), , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( cFactura ) + " subcuenta " + cCtaRet() + " no encontada.", 0 ) )
lErrorFound := .t.
end if
end if
/*
Creacion y chequeo de Cuentas de impuestos
--------------------------------------------------------------------------
*/
for each uIva in newIva
if isNum( uIva[ 3 ] )
if !ChkSubcuenta( cRutCnt(), cCodEmp, uIva[ 12 ], , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " subcuenta " + uIva[ 12 ] + " no encontada.", 0 ) )
lErrorFound := .t.
end if
if lRecargo .and. !ChkSubcuenta( cRutCnt(), cCodEmp, uIva[ 13 ], , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " subcuenta " + uIva[ 13 ] + " no encontada.", 0 ) )
lErrorFound := .t.
end if
end if
next
for n := 1 to len( aVentas )
if !ChkSubcuenta( cRuta, cCodEmp, aVentas[ n, 1 ], , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " subcuenta " + aVentas[ n, 1 ] + " no encontada.", 0 ) )
lErrorFound := .t.
end if
next
for n := 1 to len( aIvm )
if !lSimula .and. !ChkSubcuenta( cRuta, cCodEmp, aIvm[ n, 1 ], , .f., .f. )
oTree:Add( "Factura cliente : " + rtrim( nFactura ) + " subcuenta " + aIvm[ n, 1 ] + " no encontada.", 0 )
lErrorFound := .t.
end if
next
/*
Chequeo de Cuentas de Transportes
--------------------------------------------------------------------------
*/
for n := 1 to len( aTrn )
if !ChkSubcuenta( cRuta, cCodEmp, aTrn[ n, 1 ], , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " subcuenta " + aTrn[ n, 1 ] + " no encontada.", 0 ) )
lErrorFound := .t.
end if
next
/*
Chequeamos los anticipos-------------------------------------------------
*/
if nTotAnt != 0 .and. !ChkSubcuenta( cRuta, cCodEmp, cCtaAnticipo, , .f., .f. )
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " subcuenta de anticipo " + cCtaAnticipo + " no encontada.", 0 ) )
lErrorFound := .t.
end if
/*
Datos comunes a todos los Asientos
--------------------------------------------------------------------------
*/
cConcepto := "N/Fcta. N." + ( dbfFacCliT )->CSERIE + "/" + alltrim( str( (dbfFacCliT)->NNUMFAC ) + "/" + (dbfFacCliT)->CSUFFAC )
cPago := "C/Fcta. N." + ( dbfFacCliT )->CSERIE + "/" + alltrim( str( (dbfFacCliT)->NNUMFAC ) + "/" + (dbfFacCliT)->CSUFFAC )
/*
Cuadre del apunte
-------------------------------------------------------------------------
*/
nTotDebe += Round( ptaDebe, nRouDiv )
for n := 1 to len( aVentas )
if lIvaInc
nCalculo := Round( aVentas[ n, 3 ], nRouDiv )
if aVentas[ n, 2 ] != 0
nCalculo -= Round( aVentas[ n, 3 ] / ( 100 / aVentas[ n, 2 ] + 1 ), nRouDiv )
end if
else
nCalculo := Round( aVentas[ n, 3 ], nRouDiv )
end if
nTotHaber += nCalculo
next
nTotDebe += ptaRet
nTotDebe += nAcuAnt
for n := 1 to Len( aIvm )
nTotHaber += Round( aIvm[ n, 2 ], nRouDiv )
next
for n := 1 to Len( aTrn )
nTotHaber += Round( aTrn[ n, 2 ], nRouDiv )
next
for each uIva in newIva
if isNum( uIva[ 8 ] )
nTotHaber += uIva[ 8 ]
end if
if lRecargo .and. isNum( uIva[ 9 ] )
nTotHaber += uIva[ 9 ]
end if
next
nTotDebe := Round( nTotDebe, nRouDiv )
nTotHaber := Round( nTotHaber, nRouDiv )
/*
Realización de Asientos
--------------------------------------------------------------------------
*/
if lSimula .or. !lErrorFound
if lOpenDiario .or. OpenDiario( , cCodEmp )
nAsiento := contaplusUltimoAsiento()
else
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " imposible abrir ficheros de contaplus.", 0 ) )
Return .f.
end if
setAsientoIntraComunitario( isIVAComunidadEconomicaEuropea( dbfFacCliT ) )
/*
Asiento de cliente----------------------------------------------------------
*/
if lAplicacionContaplus()
aadd( aSimula, MkAsiento( nAsiento, ;
cCodDiv,;
dFecha,;
cCtaCli,;
,;
Round( ptaDebe, nRouDiv ),;
cConcepto,;
,;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
else
EnlaceA3():getInstance():Add( { "Empresa" => cEmpCnt( ( dbfFacCliT )->cSerie ),;
"Fecha" => dFecha ,;
"TipoRegistro" => '1',; // Facturas
"Cuenta" => cCtaCli,;
"DescripcionCuenta" => cTerNom,;
"TipoFactura" => '1',; // Ventas
"NumeroFactura" => cFactura,;
"DescripcionApunte" => cConcepto,;
"Importe" => Round( ptaDebe, nRouDiv ),;
"Nif" => cTerNif,;
"NombreCliente" => cTerNom,;
"CodigoPostal" => ( dbfFacCliT )->cPosCli,;
"FechaOperacion" => dFecha,;
"FechaFactura" => dFecha,;
"Moneda" => 'E',; // Euros
"Render" => 'CabeceraFactura' } )
end if
/*
Asientos de Ventas
-------------------------------------------------------------------------
*/
for n := 1 to Len( aVentas )
nCalculo := Round( aVentas[ n, 3 ], nRouDiv )
if lIvaInc
nPctIva := aVentas[ n, 2 ]
if ( lRecargo .and. aVentas[ n, 7 ] )
nPctIva += nPReq( dbfIva, aVentas[ n, 2 ] )
end if
if aVentas[ n, 2 ] != 0
nCalculo -= Round( aVentas[ n, 3 ] / ( 100 / nPctIva + 1 ), nRouDiv )
end if
end if
if lAplicacionContaplus()
aadd( aSimula, MkAsiento( nAsiento, ;
cCodDiv, ;
dFecha, ;
aVentas[ n, 1 ],;
,;
,;
cConcepto,;
nCalculo,;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
else
EnlaceA3():getInstance():Add( { "Empresa" => cEmpCnt( ( dbfFacCliT )->cSerie ),;
"Fecha" => dFecha ,;
"TipoRegistro" => '9',; // Facturas
"Cuenta" => aVentas[ n, 1 ],;
"DescripcionCuenta" => '',;
"TipoImporte" => 'C',;
"NumeroFactura" => cFactura,;
"DescripcionApunte" => cConcepto,;
"SubtipoFactura" => if( isIVAComunidadEconomicaEuropea( dbfFacCliT ), '02', '01' ),; // Ventas
"BaseImponible" => nCalculo,;
"PorcentajeIVA" => aVentas[ n, 2 ],;
"PorcentajeRecargo" => if( ( dbfFacCliT )->lRecargo, nPReq( dbfIva, aVentas[ n, 2 ] ), 0 ),;
"PorcentajeRetencion" => 0,;
"Impreso" => '01',; // 347
"SujetaIVA" => if( aVentas[ n, 2 ] != 0, 'S', 'N' ),;
"Modelo415" => ' ',;
"Analitico" => ' ',;
"Moneda" => 'E',; // Euros
"Render" => 'VentaFactura' } )
end if
next
/*
Asientos del retenciones________________________________________________________
*/
if lAplicacionContaplus() .and. ptaRet != 0
aadd( aSimula, MkAsiento( nAsiento,;
cCodDiv,;
dFecha,;
cCtaRet(),; // Cuenta de retencion
,;
ptaRet,;
cConcepto,;
,;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
end if
/*
Asientos de anticipo
-------------------------------------------------------------------------
*/
if lAplicacionContaplus() .and. nTotAnt != 0
aadd( aSimula, MkAsiento( nAsiento,;
cCodDiv,;
dFecha,;
cCtaAnticipo,;
,;
nAcuAnt,;
cConcepto,;
,;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
end if
/*
Asientos de IVM
-------------------------------------------------------------------------
*/
for n := 1 to Len( aIvm )
aadd( aSimula, MkAsiento( nAsiento, ;
cCodDiv, ;
dFecha, ;
aIvm[ n, 1 ],;
,;
,;
cConcepto,;
Round( aIvm[ n, 2 ], nRouDiv ),;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula ) )
next
/*
Asientos de transporte
-------------------------------------------------------------------------
*/
for n := 1 to Len( aTrn )
aadd( aSimula, MkAsiento( nAsiento, ;
cCodDiv, ;
dFecha, ;
aTrn[ n, 1 ],;
,;
,;
cConcepto,;
Round( aTrn[ n, 2 ], nRouDiv ),;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
next
/*
Asientos de impuestos
--------------------------------------------------------------------------
*/
for each uIva in newIva
if ( len( uIva ) >= 12 ) .and. ( uIva[ 8 ] != 0 .or. uFieldEmpresa( "lConIva" ) )
nBaseImp := uIva[ 2 ] - uIva[ 10 ]
if uFieldEmpresa( "lIvaImpEsp")
nBaseImp += uIva[ 6 ]
end if
aAsiento := MkAsiento( nAsiento, ;
cCodDiv, ;
dFecha, ;
uIva[ 12 ],; // Cuenta de impuestos
cCtaCli,; // Contrapartida
,; // Ptas. Debe
cConcepto,;
uIva[ 8 ] - uIva[ 11 ],; // Ptas. Haber
cFactura,;
nBaseImp,; // Base Imponible
uIva[ 3 ],;
if( lRecargo, uIva[ 4 ], 0 ),; // Tipo de recargo
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom )
aAdd( aSimula, aAsiento )
// Asiento SII-----------------------------------------------------
aAsientoSII := MkAsientoSII( aAsiento )
if !empty( aAsientoSII )
aadd( aAsientosSII, aAsientoSII )
end if
end if
/*
Asientos del Recargo
-------------------------------------------------------------------------
*/
if ( lRecargo .and. len( uIva ) >= 13 .and. uIva[ 9 ] != 0 )
aadd( aSimula, MkAsiento( nAsiento,;
cCodDiv,;
dFecha,;
uIva[ 13 ],;
,;
,;
cConcepto,;
uIva[ 9 ],;
cFactura,;
,;
,;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
end if
/*
Asientos de Portes exentos de recargo de equivalencia
-------------------------------------------------------------------------
*/
if ( len( uIva ) >= 14 .and. uIva[ 10 ] != 0 )
aadd( aSimula, MkAsiento( nAsiento,;
cCodDiv,;
dFecha,;
uIva[ 14 ],; // Cuenta de impuestos
cCtaCli,; // Contrapartida
,; // Ptas. Debe
cConcepto,;
uIva[ 11 ],; // Ptas. Haber
cFactura,;
uIva[ 10 ],; // Base Imponible
uIva[ 3 ],;
,;
,;
cProyecto,;
cClave,;
,;
,;
,;
lSimula,;
cTerNif,;
cTerNom ) )
end if
next
end if
// Contabilizamos desde aki A3---------------------------------------------
// if lAplicacionA3()
// oEnlaceContable:Render()
// end if
/*
Contabilizamos los pagos
----------------------------------------------------------------------------
*/
if lPago .and. !lErrorFound .and. ( dbfFacCliP )->( dbSeek( nFactura ) )
while ( ( dbfFacCliP )->cSerie + str( ( dbfFacCliP )->nNumFac ) + ( dbfFacCliP )->cSufFac == nFactura ) .and. !( dbfFacCliP )->( eof() )
ContabilizaReciboCliente( oBrw, oTree, .t., aSimula, dbfFacCliT, dbfFacCliP, dbfFPago, dbfCli, dbfDiv, .t., nAsiento )
( dbfFacCliP )->( dbSkip() )
end while
end if
/*
Ponemos la factura como Contabilizada---------------------------------------
*/
if lSimula
if lMessage
lReturn := msgTblCon( aSimula, cCodDiv, dbfDiv, !lErrorFound, pFactura,;
{|| aWriteAsiento( aSimula, cCodDiv, lMessage, oTree, pFactura, nAsiento ),;
aWriteAsientoSII( aAsientosSII ),;
lContabilizaFacturaCliente( nFactura, pFactura, nAsiento, aSimula, lPago, oTree, dbfFacCliT, dbfFacCliP ) } )
end if
else
if !lErrorFound
aWriteAsiento( aSimula, cCodDiv, lMessage, oTree, pFactura, nAsiento )
aWriteAsientoSII( aAsientosSII )
lReturn := lContabilizaFacturaCliente( nFactura, pFactura, nAsiento, aSimula, lPago, oTree, dbfFacCliT )
end if
end if
/*
Cerramos las tablas de contaplus--------------------------------------------
*/
if !lOpenDiario
CloseDiario()
end if
setAsientoIntraComunitario( .f. )
if !Empty( oBrw )
oBrw:Refresh()
end if
RETURN ( lReturn )
//---------------------------------------------------------------------------//
Static Function lContabilizaFacturaCliente( nFactura, pFactura, nAsiento, aSimula, lPago, oTree, dbfFacCliT, dbfFacCliP )
local aAsiento := atail( aSimula )
// Contabilizamos desde aki A3---------------------------------------------
if lAplicacionA3()
EnlaceA3():getInstance():Render()
end if
// Ponemos el ticket como contabilizado-------------------------------------
if dbDialogLock( dbfFacCliT )
( dbfFacCliT )->lContab := .t.
if ( getDiarioDatabaseContaplus() )->( fieldpos( "Guid" ) ) != 0
( dbfFacCliT )->cConGuid := aAsiento[ ( getDiarioDatabaseContaplus() )->( fieldpos( "Guid" ) ) ]
end if
( dbfFacCliT )->( dbUnLock() )
end if
// Mensaje------------------------------------------------------------------
if lAplicacionA3()
EnlaceA3():getInstance():WriteInfo( oTree, "Factura cliente : " + rtrim( pFactura ) + " asiento generado." )
else
oTree:Select( oTree:Add( "Factura cliente : " + rtrim( pFactura ) + " asiento generado num. " + alltrim( str( nAsiento ) ), 1 ) )
end if
// Contabilizacion de recibos-----------------------------------------------
if !empty( dbfFacCliP ) .and. lPago
if ( dbfFacCliP )->( dbseek( nFactura ) )
while ( ( dbfFacCliP )->cSerie + str( ( dbfFacCliP )->nNumFac ) + ( dbfFacCliP )->cSufFac == nFactura ) .and. !( dbfFacCliP )->( eof() )
if dbDialogLock( dbfFacCliP )
( dbfFacCliP )->lConPgo := .t.
if ( getDiarioDatabaseContaplus() )->( fieldpos( "Guid" ) ) != 0
( dbfFacCliP )->cConGuid := aAsiento[ ( getDiarioDatabaseContaplus() )->( fieldpos( "Guid" ) ) ]
end if
( dbfFacCliP )->( dbunlock() )
end if
( dbfFacCliP )->( dbskip() )
end while
end if
end if
Return ( .t. )
//---------------------------------------------------------------------------//