forked from martintoloza/ToLozano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JVMVENTA.PRG
1664 lines (1609 loc) · 65.4 KB
/
JVMVENTA.PRG
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
// Programa.: CAOVENTA.PRG >>> Martin A. Toloza Lozano <<<
// Notas....: Modulo para la Elaboracion de las Facturas
#include "Fivewin.ch"
#include "TSBrowse.ch"
#include "Btnget.ch"
MEMVAR oApl
#define CLR_PINK nRGB( 128, 150, 150) //255, 128, 128
#define CLR_NBLUE nRGB( 128, 128, 192)
FUNCTION CaoVenta()
LOCAL oDlg, oLbx, aColor[2], aRect, lNoBlink := .f.
LOCAL cTit, nA, oBtn := ARRAY(9)
LOCAL oAr, oF, oNi
If (aColor[ 1 ] := GetSysColor( COLOR_INACTIVECAPTION ) ) != ;
GetSysColor( COLOR_ACTIVECAPTION )
aColor[ 2 ] := GetSysColor( COLOR_INACTCAPTEXT )
lNoBlink := .t.
SBNoBlink()
EndIf
Empresa( .t. )
oAr := TInv() ; oAr:New()
oF := TFactura() ; oF:New()
oNi := TNits() ; oNi:New()
cTit := "Ventas - Facturas || "
oApl:oFac:nLimit := 200
oF:Iniciar()
oF:AdicArray()
SETKEY( VK_F4,{|| If( Empresa(), ( oDlg:SetText(cTit + oApl:cEmpresa),;
oF:Iniciar(), oDlg:Update() ), ), oF:oG[1]:SetFocus() } )
DEFINE DIALOG oDlg RESOURCE "FACTURAS" TITLE cTit + oApl:cEmpresa OF oApl:oWnd
REDEFINE SAY VAR oF:nSigFac ID 1 OF oDlg UPDATE COLOR "B+/W"
REDEFINE GET oF:oG[01] VAR oApl:Tipo ID 3 OF oDlg UPDATE PICTURE "!";
VALID( If( oApl:Tipo $ oF:cTipo, ( oF:nSigFac := ;
SgteNumero( "NUMFAC"+oApl:Tipo,oApl:nEmpresa,.f. ),;
oDlg:Update(), .t. ) ,;
( MsgStop( "El Tipo es ["+oF:cTipo+"]","<< OJO >>" ), .f. ) ) )
REDEFINE BTNGET oF:oG[02] VAR oF:aM[2] ID 4 OF oDlg ;
RESOURCE "BUSCAR" ;
ACTION EVAL({|| If(oF:Mostrar(), (oF:aM[2] := oF:oDb:NUMFAC ,;
oApl:nEmpresa := oF:oDb:EMPRESA ,;
oApl:Tipo := oF:oDb:TIPO ,;
oF:oG[1]:Refresh(), oF:oG[2]:lValid(.f.)),)}) ;
VALID( If( !oApl:oFac:Seek( { "empresa",oApl:nEmpresa,"numfac" ,;
oF:aM[2],"tipo",oApl:Tipo} ) .AND. oF:aM[2] # 0,;
( MsgStop("Factura NO EXISTE"), .f. ) ,;
(oF:AdicArray(), oLbx:aArray := oF:aV, oDlg:Update(),;
oF:Dscto( 0,oLbx ) ,;
If( oApl:oFac:lOK, (oF:oG[2]:oJump := oLbx), ), .t. )))
REDEFINE GET oF:oG[03] VAR oApl:oFac:FECHOY ID 6 OF oDlg UPDATE ;
VALID oF:Fechas( oApl:oFac:lOK,1 ) ;
WHEN oApl:cFecha == "SI"
REDEFINE BTNGET oF:oG[04] VAR oF:aM[3] ID 8 OF oDlg ;
RESOURCE "BUSCAR" ;
ACTION EVAL({|| If( oNi:Mostrar(), (oF:aM[3] := oNi:oDb:CODIGO,;
oF:oG[4]:Refresh() ), ) }) ;
VALID EVAL( {|| If( oNi:Buscar( oF:aM[3],,.t. ) ,;
(oApl:oFac:CODIGO_NIT := oNi:oDb:CODIGO_NIT ,;
oApl:oFac:CLIENTE := LEFT( oNi:oDb:NOMBRE,35 ) ,;
oF:aM[04] := oApl:oFac:CLIENTE ,;
oF:aM[21] := oF:FechaDev( "RETEN" ) ,;
oDlg:Update(), .t. ) ,;
(If( MsgYesNo("Desea ingresarlo","Este Nit no Existe"),;
oNi:Editar( ,.t.,,oF:aM[3] ), ),.f.) ) } ) UPDATE
REDEFINE SAY VAR oF:aM[4] ID 9 OF oDlg UPDATE
REDEFINE GET oF:oG[05] VAR oApl:oFac:CLIENTE ID 11 OF oDlg UPDATE PICTURE "@!"
REDEFINE GET oF:oG[06] VAR oApl:oFac:FECHAENT ID 13 OF oDlg UPDATE;
WHEN oApl:Tipo $ oApl:cTF
REDEFINE SAY VAR oApl:oFac:PAGINAS ID 15 OF oDlg UPDATE PICTURE "99"
REDEFINE CHECKBOX oF:oG[07] VAR oApl:oFac:EFECTIVO ID 31 OF oDlg UPDATE;
VALID ( oDlg:GoNextCtrl( oF:oG[08]:hWnd ), .t. );
WHEN oApl:oEmp:PAGOS
REDEFINE COMBOBOX oF:oG[08] VAR oF:cVende ITEMS ArrayCol( oF:aVen,1 );
ID 33 OF oDlg UPDATE;
VALID ( oApl:oFac:CODIGO_VEN := oF:aVen[oF:oG[08]:nAt,2],;
oDlg:GoNextCtrl( oF:oG[09]:hWnd ), .t. ) ;
WHEN oF:aM[2] == 0
REDEFINE GET oF:oG[09] VAR oApl:oFac:ORDEN ID 17 OF oDlg UPDATE PICTURE "@!";
WHEN oApl:Tipo == "C"
REDEFINE COMBOBOX oF:oG[14] VAR oApl:oFac:CLASECLI ITEMS oF:aCli ;
ID 45 OF oDlg UPDATE;
ON CHANGE ( oF:Dscto( 99,oLbx ) ) ;
VALID ( oDlg:GoNextCtrl( oF:oG[10]:hWnd ), .t. );
WHEN oF:aM[2] == 0
// VALID ( If( oApl:oFac:CLASECLI # nA, oF:Dscto( 99,oLbx ), ),;
// oDlg:GoNextCtrl( oF:oG[10]:hWnd ), .t. ) ;
//oF:oG[14]:bGotFocus := { || nA := oApl:oFac:CLASECLI }
REDEFINE GET oF:oG[10] VAR oApl:oFac:RETFTE ID 19 OF oDlg UPDATE PICTURE "99,999,999";
WHEN oF:aM[21]
REDEFINE GET oF:oG[11] VAR oApl:oFac:RETICA ID 21 OF oDlg UPDATE PICTURE "99,999,999";
WHEN oF:aM[21]
REDEFINE GET oF:oG[12] VAR oApl:oFac:RETIVA ID 23 OF oDlg UPDATE PICTURE "99,999,999";
WHEN oF:aM[21]
REDEFINE GET oF:oG[13] VAR oApl:oFac:RETCRE ID 25 OF oDlg UPDATE PICTURE "99,999,999";
WHEN oF:aM[21]
REDEFINE SAY VAR oF:aM[6] ID 27 OF oDlg PICTURE "999,999,999" UPDATE
REDEFINE SAY VAR oApl:nSaldo ID 29 OF oDlg PICTURE "999,999,999" UPDATE
REDEFINE SAY VAR oF:aM[7] ID 30 OF oDlg UPDATE COLOR nRGB( 255,0,0 )
ACTIVAGET(oF:oG)
REDEFINE BTNBMP oBtn[1] ID 34 OF oDlg RESOURCE "IMPRIMIR" ;
ACTION oF:Listado( oDlg,oLbx ) MESSAGE "Imprime Factura (F3)"
REDEFINE BTNBMP oBtn[2] ID 35 OF oDlg RESOURCE "REINDEZAR";
ACTION ( oF:aM[1] := .t., oLbx:KeyDown( VK_DELETE,0 ) );
MESSAGE "Borrar Código (F5)"
REDEFINE BTNBMP oBtn[3] ID 36 OF oDlg RESOURCE "DELREC" ;
ACTION oF:DelFactu( oDlg,oLbx ) MESSAGE "Anular Factura (F6)"
REDEFINE BTNBMP oBtn[4] ID 37 OF oDlg RESOURCE "NEW" ;
ACTION oF:Iniciar( oDlg,oLbx ) MESSAGE "Nueva Factura (F7)"
REDEFINE BTNBMP oBtn[5] ID 38 OF oDlg RESOURCE "DEDISCO" ;
ACTION oF:Guardar( oDlg,oLbx ) MESSAGE "Grabar Factura (F11)"
REDEFINE BTNBMP oBtn[6] ID 39 OF oDlg RESOURCE "MIRAR" ;
ACTION (oF:Abonos(), oF:Iniciar( oDlg,oLbx ));
MESSAGE "Ver los Pagos (F8)"
REDEFINE BTNBMP oBtn[7] ID 40 OF oDlg RESOURCE "MONEY" ;
ACTION MsgInfo( "Dispobible para lo que SEA" );
MESSAGE "Pagos a Cartera"
REDEFINE BTNBMP oBtn[8] ID 41 OF oDlg RESOURCE "CALC" ;
ACTION WinExec("Calc") MESSAGE "Calculadora"
REDEFINE BTNBMP oBtn[9] ID 42 OF oDlg RESOURCE "SALIR" ;
ACTION oDlg:End() MESSAGE "Regresar al Menu"
REDEFINE BROWSE oLbx ID 44 OF oDlg CELLED ; // CELLED es requerida
COLORS CLR_BLACK, CLR_NBLUE // para editar Celdas
oLbx:SetArray( oF:aV ) // Esto es necesario para trabajar con arrays
// oLbx:nFreeze := 2
oLbx:nHeightCell += 4
oLbx:nHeightHead += 4
oLbx:bKeyDown := {|nKey| If(nKey=VK_TAB, oLbx:oJump := oF:oG[3],;
If(nKey=VK_F3 , oBtn[1]:Click() ,;
If(nKey=VK_F5 , oBtn[2]:Click() ,;
If(nKey=VK_F6 , oBtn[3]:Click() ,;
If(nKey=VK_F7 , oBtn[4]:Click() ,;
If(nKey=VK_F8 , oBtn[6]:Click() ,;
If(nKey=VK_F11, oBtn[5]:Click() ,;
If(GetKeyState(VK_CONTROL) .AND. nKey=65, oF:Borrar(), )))))))) }
// If(nKey=VK_F11, oBtn[5]:Click() , ))))))) }
oLbx:SetAppendMode( oF:lNuevo ) // Activando Auto Append Mode
oLbx:SetDeleteMode( .t.,.f.,{ |nAt,oLbx| oF:DelArray(oLbx) },;
{|oLbx| oF:Dscto( 0,oLbx ) } ) // lOnOff, lConfirm, bDelete
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 1;
TITLE "Código"+CRLF+"Artículo" ;
SIZE 90 EDITABLE; // Esta columna es editable
3DLOOK TRUE, TRUE, TRUE; // Celda, Titulo, Footers
MOVE DT_MOVE_NEXT; // Cursor pasa a la Sig.Columna editable
VALID { |uVar| oF:Buscar( uVar,oLbx ) }; // don't want empty rows
ALIGN DT_LEFT, DT_CENTER ; // Celda, Titulo, Footer
PREEDIT {|uVar| oF:aM[11] := uVar, nA := oLbx:nAt ,;
oF:aM[13] := If( nA > LEN(oF:aV), 0, oF:aV[nA,11] ) };
FOOTER { || STR( oLbx:nLen,4 ) + " Items" };
WHEN oF:EditArray( oLbx )
oLbx:aColumns[01]:bPostEdit := { |uVar| oF:aV[nA,05] := oF:aM[05],;
oF:aV[nA,01] := oF:aM[11], oF:aV[nA,02] := oF:aM[12],;
oF:aV[nA,03] := oF:aM[13], oF:aV[nA,06] := oF:aM[15],;
oF:aV[nA,08] := oF:aM[14], oF:aV[nA,09] := oF:aM[16],;
oF:aV[nA,12] := oF:aM[17], oF:aV[nA,13] := oF:aM[18],;
oF:aV[nA,14] := oF:aM[14], oF:aV[nA,15] := oF:aM[19],;
oF:aV[nA,16] := oF:aM[20], oF:aV[nA,17] := oApl:aInvme[2],;
oF:Dscto( 1,oLbx ) }
// activando BtnGet para la columna 1 y habilitando una Ayuda
oLbx:SetBtnGet( 1, "Buscar", { | oGet,cVar | If( oAr:Mostrar() ,;
(cVar := oAr:oDb:CODIGO, oGet:cText( cVar ), oGet:Refresh(),;
oGet:KeyDown( VK_RETURN, 0 )), ) }, 16 )
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 2;
TITLE "Descripción" ;
SIZE 180 ;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_LEFT, DT_CENTER, DT_RIGHT;
WHEN oF:EditArray( oLbx ) ;
FOOTER "Totales->"
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 3;
TITLE "Precio"+CRLF+"Unitario" PICTURE "99,999,999";
SIZE 74 ;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_RIGHT, DT_CENTER
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 4;
TITLE "Cantidad" PICTURE "999,999.999";
SIZE 58 EDITABLE;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_RIGHT, DT_CENTER ;
POSTEDIT { |uVar| If( oLbx:lChanged, oF:Dscto( 4,oLbx,uVar ), ) } ;
VALID { |uVar| oF:DelArray( oLbx,4,uVar ) } ;
WHEN oF:EditArray( oLbx )
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 5;
TITLE "Unidad"+CRLF+"Medida" PICTURE "!!";
SIZE 50 EDITABLE;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_LEFT, DT_CENTER;
PREEDIT {|uVar| oF:aM[05] := uVar, nA := oLbx:nAt } ;
POSTEDIT {|uVar| If( oLbx:lChanged .AND. oF:aM[05] # uVar,;
oF:Dscto( 5,oLbx,uVar ), ) } ;
WHEN oF:EditArray( oLbx ) ;
VALID { |uVar| oF:Buscar( uVar,,nA ) }
// activando BtnGet para la columna 5 y habilitando (Combo Browse)
oLbx:SetBtnGet( 5, "This", { | oGet, cVar | ;
If( !GetKeyState( VK_ESCAPE ) ,;
(aRect := GetCoors( oGet:hWnd ),;
cVar := oGet:Value() ,;
cVar := oF:ComboBrowse( cVar,aRect[1],aRect[4],oGet:oWnd,oLbx:nAt ),;
oGet:cText( cVar ), oGet:Refresh(),;
oGet:KeyDown( VK_RETURN, 0 ) ), ) }, 16 )
oLbx:aColumns[ 5 ]:cMsg := "Presione F2 o Click boton para ver la lista"
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 8;
TITLE "Precio"+CRLF+"Neto" PICTURE "99,999,999" ;
SIZE 76 EDITABLE;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_RIGHT, DT_CENTER, DT_RIGHT;
VALID { |uVar| oF:DelArray( oLbx,8,uVar ) } ;
FOOTER { || TRANSFORM( oF:aM[09], "99,999,999" ) };
PREEDIT {|uVar| nA := oLbx:nAt, oF:aM[13] := oF:aV[nA,03] };
POSTEDIT {|uVar| If( oLbx:lChanged .OR. oF:aM[13] # uVar ,;
oF:Dscto( 8,oLbx,uVar ), ) } ;
WHEN oF:EditArray( oLbx )
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 6;
TITLE "%"+CRLF+"Dscto." PICTURE "999.99" ;
SIZE 48 EDITABLE;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_RIGHT, DT_CENTER ;
VALID { |uVar| If( Rango( uVar,0,100 ), .t., ;
(MsgStop( "El Porcentaje debe ser entre 0 y 100",">>OJO<<" ), .f.)) };
POSTEDIT { |uVar| If( oLbx:lChanged, oF:Dscto( 6,oLbx,uVar ), ) };
WHEN oF:EditArray( oLbx )
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 7;
TITLE "Descuento" PICTURE "99,999,999" ;
SIZE 74 EDITABLE;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_RIGHT, DT_CENTER, DT_RIGHT;
VALID { |uVar| oF:DelArray( oLbx,7,uVar ) };
FOOTER { || TRANSFORM( oF:aM[08], "99,999,999" ) };
POSTEDIT { |uVar| If( oLbx:lChanged, oF:Dscto( 7,oLbx,uVar ), ) };
WHEN oF:EditArray( oLbx )
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 9;
TITLE "Monto"+CRLF+"I.V.A" PICTURE "99,999,999" ;
SIZE 74 EDITABLE;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_RIGHT, DT_CENTER, DT_RIGHT;
FOOTER { || TRANSFORM( oF:aM[10], "99,999,999" ) };
POSTEDIT { |uVar| If( oLbx:lChanged, oF:Dscto( 0,oLbx,uVar ), ) };
WHEN oF:EditArray( oLbx )
ADD COLUMN TO BROWSE oLbx DATA ARRAY ELEMENT 10;
TITLE "Indicador" ;
SIZE 80 ;
3DLOOK TRUE, TRUE, TRUE;
MOVE DT_MOVE_NEXT;
ALIGN DT_LEFT, DT_CENTER
// Asignando Valores por defaults para nueva Fila creada con Auto Append.
oLbx:aDefault := { SPACE(12), SPACE(40), 0, 1, "UN", 0, 0, 0, 0, " ", 0, .f., 1, 0, 1, "", 0 }
oLbx:SetColor( { 2, 6, 15 }, ;
{ {|| If( oLbx:nAt % 2 == 0, CLR_PINK, CLR_NBLUE ) },;
{ CLR_WHITE, CLR_HRED }, ; // degraded cursor
CLR_GRAY } ) // grid lines color
ACTIVATE DIALOG oDlg CENTERED ;
VALID !GetKeyState( VK_ESCAPE )
If( lNoBlink, SBNoBlink( aColor[1], aColor[2] ), Nil )
oApl:oEmp:Seek( {"empresa",oF:nOptica} )
oF:oMvc:Destroy()
oF:oMvd:Destroy()
oF:oVen:Destroy()
SETKEY( VK_F4,{||Empresa()} )
nEmpresa( .f. )
RETURN NIL
//------------------------------------//
CLASS TFactura FROM TNits
DATA aDF AS ARRAY INIT { .16,595000,.035,.0045,.75 }
DATA aM AS ARRAY INIT { .f.,0,0,"",0,0,"",0,0,0,"","",0,0,0,0,.f.,0,0,"",.f.,.f.,"" }
DATA aCli AS ARRAY INIT { " " }
DATA aPag AS ARRAY INIT ArrayCombo( "FPAGO" )
DATA aVen AS ARRAY INIT { {" ",0} }
DATA cVende INIT " "
DATA lNuevo INIT .t.
DATA oG INIT ARRAY(14)
DATA aCta, aPrv, aV, aUM, cTipo, lCierre, nSigFac, nOptica
DATA oMvc, oMvd, oVen
METHOD NEW( xCoti ) Constructor
METHOD Iniciar( oDlg,oLbx )
METHOD AdicArray()
METHOD EditArray( oLbx )
METHOD Buscar( xBuscar,oLbx,nA )
METHOD Dscto( nPos,oLbx,mGetVar )
METHOD DelArray( oLbx,nCol,uVar )
METHOD DelFactu( oDlg,oLbx )
METHOD FechaDev( cMsg,dFec )
METHOD Fechas( lOK,nMsg )
METHOD Guardar( oDlg,oLbx )
METHOD Listado( oDlg,oLbx )
METHOD Abonos()
METHOD Borrar( oLbx,oLbf )
METHOD Editar( lNuevo,oLbx )
METHOD Mostrar( lAyuda,nOrd )
METHOD Cambios( lCambio,nAbono,nPago )
METHOD ComboBrowse( cState,nRow,nCol,oWnd,nA )
METHOD Paginas( cFac,nFac )
METHOD Retencion( nSubTot )
ENDCLASS
//------------------------------------//
METHOD New( xCoti ) CLASS TFactura
If xCoti == NIL
Super:New( oApl:oFac )
::oVen := oApl:Abrir( "cadfactd","empresa, numfac, tipo",,,50 )
Else
Super:New( xCoti )
:: oG := ARRAY(7)
::oVen := oApl:Abrir( "cadcotid","empresa, numero",,,50 )
EndIf
::aOrden := { {"<None> ",1},{"Factura",3},;
{"Nombre" ,6},{"Fecha" ,5} }
::bNew := ::bEditar := ::bVer := {||.t. }
::aCta := Cuentas( 3,1 )
::oMvc := oApl:Abrir( "cgemovc" ,"empresa, ano_mes, control",.t.,,5 )
::oMvd := oApl:Abrir( "cgemovd" ,"empresa, ano_mes, control",.t.,,10 )
::aPrv := Privileg( "FACTURAS" )
::aCli := Buscar( "SELECT desplegar FROM cadcombo WHERE tipo = 'CLIENTE' ORDER BY retornar","CM",,9 )
If LEN( ::aCli ) == 0
::aCli := { "" }
EndIf
::aUM := Buscar( "SELECT nombre, codigo_nit FROM vendedor ORDER BY nombre","CM",,9 )
If LEN( ::aUM ) > 0
AEVAL( ::aUM, {| e | AADD( ::aVen,{ e[1],e[2] } ) } )
EndIf
::aUM := ArrayCombo( "MEDIDAS",1 )
oApl:oFac:xBlank()
RETURN NIL
//------------------------------------//
METHOD Iniciar( oDlg,oLbx ) CLASS TFactura
LOCAL cTipo
If oDlg == NIL
::nOptica := oApl:nEmpresa
::nSigFac := SgteNumero( "NUMFAC"+oApl:Tipo,::nOptica,.f. )
cTipo := ALLTRIM(oApl:oEmp:TIPOFAC)
oApl:Tipo := LEFT( Saca( @cTipo,"," ),1 )
oApl:Tipo := oApl:cFT
::cTipo := cTipo
ElseIf VALTYPE( oDlg ) == "O"
AEVAL( ::aM, {|xV,nI| ::aM[nI] := {"",CTOD(""),.f.,0}[AT(VALTYPE(xV),"CDLN")] } )
::AdicArray() ; oLbx:aArray := ::aV
oApl:oFac:xBlank()
oDlg:Update() ; oLbx:Refresh()
::oG[01]:SetFocus()
Else
If oApl:oFac:CLASECLI == 2 .AND. oApl:oInv:PUNIDAD > 0
//Mayorista
::aM[13] := oApl:oInv:PUNIDAD
ElseIf oApl:oFac:CLASECLI == 3
//MsgInfo( "Especial" )
::aM[13] := oApl:oInv:PCOSTO +;
ROUND( oApl:oInv:PCOSTO * 3/100,0 )
Else
::aM[13] := oApl:oInv:PPUBLI
EndIf
EndIf
RETURN NIL
//------------------------------------//
METHOD AdicArray() CLASS TFactura
LOCAL aRes, hRes, nL
If ::aM[2] == 0
::aM[7] := ""
::lNuevo:= .t.
oApl:nSaldo := 0
oApl:nEmpresa := ::nOptica
oApl:oFac:lOK := .f.
oApl:oFac:FECHOY := oApl:dFec
oApl:oFac:FECHAENT := oApl:dFec + 30
oApl:oFac:CODIGO_NIT:= 1
oApl:oFac:PAGINAS := 1
oApl:oFac:CLASECLI := 1
If oApl:oEmp:PAGOS .AND. oApl:Tipo # "C"
oApl:oFac:EFECTIVO := .T.
EndIf
oApl:oFac:INDICADOR := If( oApl:oFac:EFECTIVO , "C", "P" )
//oApl:oFac:INDICADOR := If( oApl:Tipo $ oApl:cTF, "P", "C" )
Else
oApl:cPer:= NtChr( oApl:dFec,"1" )
oApl:lFam:= SaldoFac( ::aM[2] )
::lNuevo := !oApl:lEnLinea
If ::nOptica == oApl:oFac:EMPRESA
nL := AT( oApl:oFac:INDICADOR,"APCN" ) +1
::aM[7] := {"","ANULADA","PENDIENTE","CANCELADA","N.Credito"}[nL]
Else
::aM[7] := ArrayValor( oApl:aOptic,STR(oApl:oFac:EMPRESA,2) )
EndIf
EndIf
::aM[22] := oApl:oFac:EFECTIVO
::Fechas( .f. )
::aV := {}
aRes := "SELECT v.codigo, v.ppubli, v.cantidad, v.unidadmed, v.despor, v.desmon," +;
" v.precioven, v.montoiva, v.indicador, v.row_id, v.pcosto, c.numero "+;
"FROM cadfactd v LEFT JOIN cadnotac c USING(empresa, numfac)" +;
" LEFT JOIN cadnotad d" +;
" ON c.empresa = d.empresa" +;
" AND c.numero = d.numero" +;
" AND v.codigo = d.codigo " +;
"WHERE v.empresa = " + LTRIM(STR(oApl:nEmpresa))+;
" AND v.numfac = " + LTRIM(STR(::aM[2])) +;
" AND v.tipo = " + xValToChar( oApl:Tipo ) +;
" GROUP BY v.row_id"
hRes := If( MSQuery( oApl:oMySql:hConnect,aRes ) ,;
MSStoreResult( oApl:oMySql:hConnect ), 0 )
nL := MSNumRows( hRes )
While nL > 0
aRes := MyReadRow( hRes )
AEVAL( aRes, { | xV,nP | aRes[nP] := MyClReadCol( hRes,nP ) } )
If aRes[09] == "N"
aRes[09] += "C." + LTRIM(STR(aRes[12]))
EndIf
::Buscar( aRes[01] )
::aM[14] := ROUND( (aRes[07] + aRes[06]) / aRes[03],2 )
AADD( ::aV,{ aRes[01], ::aM[12] , aRes[02],;
aRes[03], aRes[04] , aRes[05],;
aRes[06], aRes[07] , aRes[08],;
aRes[09], aRes[10], ::aM[17], ::aM[18],;
::aM[14], ::aM[19], ::aM[20], aRes[11] } )
nL --
EndDo
MSFreeResult( hRes )
If LEN( ::aV ) == 0
AADD( ::aV,{ SPACE(12), SPACE(40), 0, 1, "UN", 0, 0, 0, 0, " ", 0, .f., 1, 0, 1, "", 0 } )
EndIf
oApl:oNit:Seek( {"codigo_nit",oApl:oFac:CODIGO_NIT} )
::aM[03] := oApl:oNit:CODIGO ; ::aM[4] := oApl:oNit:NOMBRE
::aM[06] := oApl:oFac:TOTALFAC
::aM[21] := ::FechaDev( "RETEN" )
::cVende := ArrayValor( ::aVen,oApl:oFac:CODIGO_VEN )
//::cVende := ArrayValor( ::aVen,oApl:oFac:CODIGO_VEN,{|xV| oApl:oFac:CODIGO_VEN := xV} )
SysRefresh()
RETURN NIL
//------------------------------------//
METHOD EditArray( oLbx ) CLASS TFactura
LOCAL lEdit := .t., nA := oLbx:nAt, nF
If nA > LEN(::aV)
nF := If( nA > 2, 1, nA-1 )
If EMPTY( ::aV[nF,01] ) .OR. oLbx:nCell # 1
MsgStop( "Primero Digite Código del Artículo","Nuevo" )
oLbx:nAt := oLbx:nLen := oLbx:nRowPos := nA
oLbx:nCell := 1 ; lEdit := .f.
oLbx:HiliteCell( 1 ) ; oLbx:Refresh(.t.)
oLbx:DrawSelect()
EndIf
Else
If EMPTY( ::aV[nA,01] ) .AND. oLbx:nCell # 1
MsgStop( "Primero Digite Código del Artículo" )
oLbx:nCell := 1 ; lEdit := .f.
oLbx:HiliteCell( 1 ) ; oLbx:Refresh()
ElseIf oApl:oFac:lOK .AND. (!::aPrv[2] .OR. LEFT( ::aV[nA,10],1 ) $ "AD")
MsgStop( "Este Registro no se Puede Modificar","Lo Siento" )
lEdit := .f.
ElseIf oLbx:nCell == 6 .AND. !::aPrv[1]
oLbx:nCell := 7 ; lEdit := .f.
oLbx:HiliteCell( 7 ) ; oLbx:Refresh( .F. )
EndIf
EndIf
RETURN lEdit
//------------------------------------//
METHOD Buscar( xBuscar,oLbx,nA ) CLASS TFactura
LOCAL lOK := .t.
If nA # NIL
If ::aV[nA,16] # xBuscar
If Buscar( {"codcon",::aV[nA,15],"de",xBuscar},"convertir","multipor",8,,4 ) == 0
MsgStop( "No Existe Unidad de Medida","<< OJO >>" )
lOK := .f.
EndIf
EndIf
Else
//If (lOK := oApl:oInv:Seek( {"codigo",xBuscar} ))
If (lOK := BuscaCob( @xBuscar ))
If oApl:Tipo # "X"
::aM[18] := If( oApl:oEmp:TREGIMEN == 1 .OR. !oApl:oInv:INDIVA, 0,;
If( oApl:oInv:IMPUESTO == 0, ::aDF[1],;
ROUND(oApl:oInv:IMPUESTO/100,2) )) + 1
Else
::aM[18] := 1
EndIf
::aM[11] := xBuscar
::aM[12] := oApl:oInv:DESCRIP
::aM[13] := oApl:oInv:PPUBLI
::aM[17] := If( ::aM[18] > 1 .AND. oApl:Tipo $ "CZ", .t., .f. )
::aM[19] := oApl:oInv:CODCON
::aM[20] := oApl:oInv:UNIDADMED
::aM[23] := oApl:oInv:AJUSTE_ESP
If oLbx == NIL
RETURN NIL
EndIf
nA := oLbx:nAt
If nA > LEN(::aV) .OR. ::aV[nA,1] # xBuscar
If NtChr( xBuscar ) >= oApl:oEmp:LENCOD
If SaldoInv( xBuscar,oApl:cPer,1 ) <= 0
If !MsgNoYes( "SIN Existencia="+STR(oApl:aInvme[1])+" CONTINUA ?",::aM[12] )
RETURN .f.
EndIf
EndIf
Else
oApl:aInvme[2] := 0
EndIf
// oApl:aInvme[2] := Buscar( "SELECT sf_pcosto(" + LTRIM(STR(oApl:nEmpresa))+;
// ", " + ALLTRIM( xBuscar ) +;
// ", " + xValToChar(oApl:oFac:FECHOY) +;
// ") FROM DUAL","CM",,,,4 )
If oApl:aInvme[2] == 0 .OR. oApl:aInvme[2] > oApl:oInv:PCOSTO
oApl:aInvme[2] := oApl:oInv:PCOSTO
EndIf
If oApl:oInv:DESPOR > 0
::aM[15] := If( MsgNoYes( TRANSFORM(oApl:oInv:DESPOR,"999.99%"),;
"Le Aplico este Descuento" ), oApl:oInv:DESPOR, 0 )
EndIf
::aM[05] := oApl:oInv:UNIDADMED
//::aM[13] := oApl:oInv:PPUBLI
::Iniciar( 1 )
//MsgInfo( TRANSFORM(::aM[18],"999.99"),"NUEVO" )
If ::aM[17]
::aM[14] := ROUND( ::aM[13] / ::aM[18],2 )
Else
::aM[14] := ::aM[13]
EndIf
/*
If ::aM[17]
::aM[13] := ROUND( ::aM[13] / ::aM[18],0 )
::aM[14] := ::aM[13]
Else
::aM[14] := ROUND( ::aM[13] / ::aM[18],0 )
EndIf
*/
::aM[16] := ::aM[13] - ::aM[14]
Else
::aM[05] := ::aV[nA,5]
::aM[13] := ::aV[nA,3]
::aM[14] := ROUND((::aV[nA,8] + ::aV[nA,9]) / ::aM[18],2 )
::aM[14] := ROUND((::aV[nA,7] + ::aM[14]) / ::aV[nA,4],2 )
::aM[15] := ::aV[nA,6]
::aM[16] := ::aV[nA,9]
EndIf
ElseIf !EMPTY( xBuscar )
MsgStop( "Este Código NO EXISTE !!!",xBuscar )
EndIf
EndIf
RETURN If( EMPTY( xBuscar ), .f., lOK )
//------------------------------------//
METHOD Dscto( nPos,oLbx,mGetVar ) CLASS TFactura
LOCAL nSubTot, nA := oLbx:nAt
do Case
Case nPos == 5 // UnidadMed
If oApl:oInv:CODIGO # ::aV[nA,1]
oApl:oInv:Seek( {"codigo",::aV[nA,1]} )
EndIf
If oApl:oInv:PUNIDAD > 0
::aM[13] := oApl:oInv:PUNIDAD
Else
::aM[13] := AFormula( ::aV[nA,3],mGetVar,::aV[nA,16],::aV[nA,15] )
EndIf
::aV[nA,03] := ROUND( ::aM[13] / If( ::aV[nA,12], 1, ::aV[nA,13] ),0 )
::aV[nA,05] := mGetVar
Case nPos == 6 // % Descuento
::aV[nA,06] := If( mGetVar == 0, 0, ::aV[nA,06] )
Case nPos == 8 // Precio Neto
If ::aV[nA,04] > 1 .AND. mGetVar > 0
If !MsgYesNo( "Este es el Precio Unitario","DIVIDIR" )
mGetVar := ROUND( mGetVar/::aV[nA,04],2 )
EndIf
EndIf
::aV[nA,03] := mGetVar
If oApl:oEmp:PRINTIVA .AND. ::aV[nA,12] .AND. mGetVar > 0
//If MsgYesNo( "Precio con IVA incluido","I.V.A."+STR(::aV[nA,13],5,2) )
mGetVar := ROUND( mGetVar / ::aV[nA,13],2 )
//EndIf
EndIf
::aV[nA,14] := mGetVar
EndCase
If Rango( nPos,1,8 )
nSubTot := ROUND( ::aV[nA,14] * ::aV[nA,04],0 )
::aV[nA,7] := If( nPos == 7, mGetVar, If( ::aV[nA,06] = 0, ::aV[nA,07],;
ROUND( nSubTot * ::aV[nA,6] / 100,0 ) ) )
nSubTot -= ::aV[nA,7]
::aV[nA,8] := ROUND( nSubTot / If( ::aV[nA,12], 1, ::aV[nA,13] ),0 )
If ::aV[nA,7] == 0 .AND. oApl:oEmp:PRINTIVA
::aV[nA,9] := ROUND( ::aV[nA,3] * ::aV[nA,04],0 ) - ::aV[nA,8]
Else
::aV[nA,9] := ROUND( ::aV[nA,8] * ::aV[nA,13],0 ) - ::aV[nA,8]
EndIf
/*
nSubTot := ROUND( ::aV[nA,03] * ::aV[nA,04],0 )
::aV[nA,7] := If( nPos == 7, mGetVar, If( ::aV[nA,06] = 0, ::aV[nA,07],;
ROUND( nSubTot * ::aV[nA,6] / 100,0 ) ) )
nSubTot -= ::aV[nA,7]
::aV[nA,8] := ROUND( nSubTot / If( ::aV[nA,12], 1, ::aV[nA,13] ),0 )
::aV[nA,9] := ROUND( ::aV[nA,8] * ::aV[nA,13],0 ) - ::aV[nA,8]
// ::aV[nA,8] := nSubTot - ::aV[nA,7]
// ::aV[nA,9] := If( ::aV[nA,12], ROUND( ::aV[nA,8] * ::aV[nA,13],0 ), nSubTot - ::aV[nA,8] )
*/
ElseIf nPos == 99
//MsgInfo( "Recalcular" )
FOR nA := 1 TO LEN( ::aV )
If !EMPTY( ::aV[nA,01] ) .AND. LEFT( ::aV[nA,10],1 ) == " "
oApl:oInv:Seek( {"codigo",::aV[nA,01]} )
::Iniciar( 1 )
If ::aV[nA,12]
::aM[14] := ROUND( ::aM[13] / ::aV[nA,13],2 )
Else
::aM[14] := ::aM[13]
EndIf
::aV[nA,03] := ::aM[13]
::aV[nA,08] := ::aM[14]
::aV[nA,09] := ::aM[13] - ::aM[14]
::aV[nA,14] := ::aM[14]
EndIf
NEXT nA
EndIf
::aM[08] := ::aM[09] := ::aM[10] := 0
AEVAL( ::aV, { | e | ::aM[08] += e[ 7 ], ::aM[09] += e[ 8 ], ::aM[10] += e[ 9 ] } )
::aM[09] += ::aM[10]
If oApl:oFac:TOTALDES # ::aM[08] .OR. oApl:oFac:TOTALIVA # ::aM[10] .OR. ;
oApl:oFac:TOTALFAC # ::aM[09] .OR. oLbx:lChanged
oApl:oFac:TOTALDES := ::aM[08] ; oApl:oFac:TOTALIVA := ::aM[10]
oApl:oFac:TOTALFAC := ::aM[09]
::Retencion( (::aM[09] - ::aM[10]) )
AEVAL( ::oG, {|o| o:Refresh() },10,4 )
EndIf
oLbx:Refresh() ; oLbx:DrawFooters()
RETURN NIL
//------------------------------------//
METHOD DelArray( oLbx,nCol,uVar ) CLASS TFactura
LOCAL lSi := .t., nA := oLbx:nAt
If nCol == NIL
lSi := .f.
If ::aV[nA,11] == 0
lSi := .t.
ElseIf ::aM[1] .AND. oApl:oFac:lOK .AND. ::aPrv[3]
If MsgNoYes( "Elimina este Código",::aV[nA,01] )
::oVen:Seek( {"row_id",::aV[nA,11]} )
If LEFT( ::aV[nA,10],1 ) $ "AD"
Actualiz( ::aV[nA,1],-::aV[nA,4],::oVen:FECDEV,7,,::aV[nA,5] )
EndIf
Actualiz( ::aV[nA,1],-::aV[nA,4],oApl:oFac:FECHOY,2,,::aV[nA,5] )
::oVen:Delete(.f.,1)
lSi := .t.
EndIf
EndIf
::aM[1] := .f.
ElseIf nCol == 4
If uVar <= 0
MsgStop( "La Cantidad debe ser Mayor de 0","<< OJO >>" )
lSi := .f.
EndIf
ElseIf nCol == 7
If uVar < 0
MsgStop( "Descuento tiene que ser Positivo","<<OJO>>" )
lSi := .f.
ElseIf uVar > ::aV[nA,08]
uVar := " Descuento" + TRANSFORM( uVar,"$999,999,999" ) + CRLF +;
"Precio Neto" + TRANSFORM( ::aV[nA,07]+::aV[nA,08],"$999,999,999" )
MsgStop( uVar,"Descuento MAYOR que el Precio Neto" )
lSi := .f.
EndIf
ElseIf nCol == 8
oApl:aInvme[2] := AFormula( ::aV[nA,17],::aV[nA,05],::aV[nA,16],::aV[nA,15] )
oApl:aInvme[2] := ROUND( ::aV[nA,4] * oApl:aInvme[2],2 )
If uVar < 0
MsgStop( "Precio Neto tiene que ser Positivo","<<OJO>>" )
lSi := .f.
ElseIf uVar < oApl:aInvme[2]
uVar := "Precio Neto" + TRANSFORM( uVar,"$999,999,999" ) + CRLF +;
"Precio Costo" + TRANSFORM( oApl:aInvme[2],"$999,999,999" )
MsgStop( uVar,"Precio Costo MAYOR que el Precio Neto" )
lSi := .f.
EndIf
EndIf
RETURN lSi
//------------------------------------//
METHOD DelFactu( oDlg,oLbx ) CLASS TFactura
LOCAL dFecdev, cPerF := oApl:cPer, mCant, nTipo, nR
If !oApl:oFac:lOK
If EMPTY( ::aV[1,01] )
oApl:oFac:INDICADOR := "A"
::Guardar( oDlg,oLbx )
EndIf
ElseIf oApl:oFac:INDICADOR == "A"
If MsgNoYes( "Está Factura","ACTIVA" )
oApl:oFac:INDICADOR := If( oApl:oFac:EFECTIVO, "C", "P" )
oApl:oFac:Update(.f.,1)
If !oApl:oFac:EFECTIVO
oApl:lFam := SaldoFac( ::aM[2] )
GrabaSal( ::aM[2],1,-oApl:oFam:ABONOS )
EndIf
If oApl:oFac:FECHOY >= CTOD("01.01.2008")
cPerF := "empresa = " + LTRIM(STR(oApl:nEmpresa))+;
" AND ano_mes = " + xValToChar(oApl:cPer ) +;
" AND fuente = 3" +;
" AND control = " + LTRIM(STR(oApl:oFac:CONTROL))
MSQuery( oApl:oMySql:hConnect,"UPDATE cgemovc SET estado = 1 WHERE " + cPerF )
EndIf
EndIf
Else
If Login( "Desea Anular esta Factura" )
dFecdev := ::FechaDev( "Fecha Anulación" )
oApl:cPer := NtChr( dFecdev,"1" )
nTipo := If( oApl:cPer > cPerF, 7, 2 )
If oApl:oFac:FECHOY >= CTOD("01.01.2008")
cPerF := "empresa = " + LTRIM(STR(oApl:nEmpresa))+;
" AND ano_mes = " + xValToChar( cPerF ) +;
" AND control = " + LTRIM(STR(oApl:oFac:CONTROL))
::oMvc:Seek( cPerF,"CM" )
::oMvd:dbEval( {|o| o:EMPRESA := -9, Acumular( ::oMvc:ESTADO,o,3,3,.f.,.f. ) },cPerF )
Guardar( "UPDATE cgemovc SET estado = 2 WHERE " + cPerF,"cgemovc" )
EndIf
oApl:oFac:INDICADOR := "A" ; oApl:oFac:FECHAENT := dFecdev
oApl:oFac:Update(.f.,1)
If oApl:oEmp:PAGOS .AND. !oApl:oFac:EFECTIVO
PagosFac( "A" )
EndIf
If !oApl:oFac:EFECTIVO
oApl:lFam := SaldoFac( ::aM[2] )
GrabaSal( ::aM[2],1,oApl:nSaldo )
cPerF := If( oApl:lEnLinea, "DELETE FROM cadpagos" ,;
"UPDATE cadpagos SET indicador = 'A'" ) +;
" WHERE empresa = " + LTRIM(STR(oApl:nEmpresa))+;
" AND numfac = " + LTRIM(STR(::aM[2])) +;
" AND tipo = '" + oApl:Tipo + "'"
MSQuery( oApl:oMySql:hConnect,cPerF )
EndIf
FOR nR := 1 TO LEN( ::aV )
If ::aV[nR,11] > 0 .AND. LEFT( ::aV[nR,10],1 ) == " "
::oVen:Seek( {"row_id",::aV[nR,11]} )
mCant := ::aV[nR,4] * If( nTipo = 2, -1, 1 )
Actualiz( ::aV[nR,1],mCant,dFecdev,nTipo,,::aV[nR,5] )
If oApl:lEnLinea .AND. nTipo == 2
::oVen:Delete(.f.,1)
Else
::oVen:INDICADOR := If( nTipo == 2, "A", "D" )
::oVen:FECDEV := dFecdev ; ::oVen:Update(.f.,1)
EndIf
EndIf
NEXT nR
::Iniciar( oDlg,oLbx )
EndIf
EndIf
RETURN NIL
//------------------------------------//
METHOD FechaDev( cMsg,dFec ) CLASS TFactura
If cMsg == "RETEN"
If (oApl:oNit:CODIGO > 800000000 .AND.;
oApl:oNit:CODIGO < 999999999) .AND. oApl:Tipo == "C"
dFec := .t.
Else
dFec := .f.
EndIf
Else
dFec := oApl:dFec
WHILE !oApl:lEnLinea
dFec := MsgDate( dFec,cMsg )
If dFec >= oApl:oFac:FECHOY
If MsgYesNo( DTOC(dFec)+" Es Correcta Fecha",cMsg )
EXIT
EndIf
EndIf
EndDo
EndIf
RETURN dFec
//------------------------------------//
METHOD Fechas( lOK,nMsg ) CLASS TFactura
LOCAL aFec, nR, lSI := .t.
If lOK
aFec := { oApl:oFac:XColumn( 5 ),oApl:oFac:FECHOY,oApl:cPer,::lCierre,.t.,;
"empresa = " + LTRIM(STR(oApl:nEmpresa)) +;
" AND ano_mes = " + xValToChar(oApl:cPer ) +;
" AND control = " + LTRIM(STR(oApl:oFac:CONTROL)) }
If (aFec[5] := ::Fechas( .f.,1 ))
If (aFec[3] == LEFT( DTOS(aFec[2]),6 ))
If oApl:oFac:FECHOY >= CTOD("01.01.2008")
Guardar( "UPDATE cgemovc SET fecha = " + xValToChar(aFec[2]) +;
" WHERE " + aFec[6],"cgemovc" )
EndIf
Guardar( oApl:oFac,.f.,.f. )
ElseIf MsgYesNo( "QUIERE HACER EL CAMBIO","VA A CAMBIAR DE MES" )
FOR nR := 1 TO LEN( ::aV )
If ::aV[nR,11] > 0
::oVen:Seek( {"row_id",::aV[nR,11]} )
Actualiz( ::aV[nR,1],-::aV[nR,4],aFec[1],2,,::aV[nR,5] )
Actualiz( ::aV[nR,1], ::aV[nR,4],aFec[2],2,,::aV[nR,5] )
EndIf
NEXT nR
If oApl:oFac:CONTROL > 0 .AND. oApl:oFac:FECHOY >= CTOD("01.01.2008")
oApl:oFac:CONTROL := SgteCntrl( "Control",oApl:cPer,.t. )
::oMvc:Seek( aFec[6],"CM" )
::oMvc:ANO_MES := oApl:cPer
::oMvc:FECHA := aFec[2]
::oMvc:CONTROL := oApl:oFac:CONTROL
Guardar( ::oMvc,.f.,.f. )
::oMvd:dbEval( {|o| Acumular( ::oMvc:ESTADO,o,5,5,.f.,.f. ) ,;
o:ANO_MES := oApl:cPer, o:CONTROL := ::oMvc:CONTROL,;
Acumular( ::oMvc:ESTADO,o,2,2,.f.,.f. ) }, aFec[6] )
EndIf
Guardar( oApl:oFac,.f.,.f. )
If !oApl:oFac:EFECTIVO
If oApl:oFam:Seek( { "empresa",oApl:nEmpresa,"numfac",::aM[2],;
"tipo",oApl:Tipo,"anomes",aFec[3] } )
oApl:oFam:ANOMES := oApl:cPer
Guardar( oApl:oFam,.f.,.f. )
EndIf
EndIf
Guardar( oApl:oFac,.f.,.f. )
Else
aFec[5] := .f.
EndIf
EndIf
If (lSI := aFec[5])
MsgInfo( "El cambio de Fecha","HECHO" )
Else
lSI := If( EMPTY( aFec[2] ) .OR. ::lCierre, .t., .f. )
oApl:oFac:FECHOY := aFec[1]
oApl:cPer := aFec[3]
::lCierre := aFec[4]
EndIf
ElseIf EMPTY( oApl:oFac:FECHOY )
MsgStop( "No puede ir en Blanco","FECHA" )
lSI := .f.
Else
oApl:cPer := NtChr( oApl:oFac:FECHOY,"1" )
::lCierre := Buscar( {"empresa",oApl:nEmpresa,"ano_mes",oApl:cPer},;
"cgecntrl","cierre",8,,3 )
If ::lCierre .AND. nMsg # NIL
MsgStop( "Ya esta CERRADO","Periodo "+oApl:cPer )
lSI := .f.
Else
::aDF := PIva( oApl:cPer )
EndIf
EndIf
RETURN lSI
//------------------------------------//
METHOD Guardar( oDlg,oLbx ) CLASS TFactura
LOCAL lCambio, nAbono, nPago, nR, cFactu := "Numfac"+oApl:Tipo
If EMPTY( ::aV[1,1] ) .AND. oApl:oFac:INDICADOR # "A"
MsgInfo( "Factura no Tiene ningun Items" )
RETURN NIL
EndIf
nAbono := oApl:oFac:TOTALFAC -;
oApl:oFac:RETFTE - oApl:oFac:RETICA - oApl:oFac:RETIVA - oApl:oFac:RETCRE
nPago := nR := 0
oApl:cPer := NtChr( oApl:oFac:FECHOY,"1" )
If !oApl:oFac:lOK
nR := SgteNumero( cFactu,oApl:nEmpresa,.f. )
If !MsgYesNo("Factura #"+STR(nR),"Graba esta")
RETURN NIL
EndIf
// While .t.
nR := SgteNumero( cFactu,oApl:nEmpresa,.t. )
// If !BuscaDup( nR )
// EXIT
// EndIf
// EndDo
If !oApl:lEnLinea
oApl:dFec := oApl:oFac:FECHOY
ElseIf oApl:oFac:FECHOY < oApl:oEmp:FEC_HOY
oApl:oFac:FECHOY := oApl:oEmp:FEC_HOY
oApl:oFac:FECHAENT := oApl:oEmp:FEC_HOY + 3
oApl:cPer:= NtChr( oApl:oFac:FECHOY,"1" )
EndIf
oApl:oFac:EMPRESA := oApl:nEmpresa
oApl:oFac:TIPO := oApl:Tipo
oApl:oFac:NUMFAC := nR
oApl:oFac:Append( .t. )
oApl:nSaldo := nAbono
::nSigFac := oApl:oFac:NUMFAC + 1
oApl:oFac:PAGINAS := ::Paginas( cFactu,nR )
cFactu := "SI"
lCambio := .t. ; oApl:lFam := .f.
Else
If (lCambio := oApl:oFac:TOTALFAC # ::aM[6])
If !MsgNoYes( TRANSFORM( oApl:oFac:TOTALFAC,"NUEVO 999,999,999" ) +;
TRANSFORM( ::aM[6]," - VIEJO 999,999,999" ),"EL TOTAL ES DIFERENTE" )
RETURN NIL
EndIf
EndIf
/*
If !oApl:oFac:EFECTIVO .OR. oApl:Tipo $ oApl:cTF
If (oApl:lFam := SaldoFac( ::aM[2] ))
nPago := nAbono - (oApl:nSaldo + oApl:oFam:ABONOS - oApl:oFam:DEBITO)
If nPago # 0
//oApl:oFam:SALDO += oApl:nSaldo := nAbono - oApl:oFam:ABONOS + oApl:oFam:DEBITO
//Guardar( oApl:oFam,.f.,.f. )
cFactu := "UPDATE cadfactm SET saldo = saldo + " + LTRIM(STR(nPago))+;
" WHERE empresa = " + LTRIM(STR(oApl:nEmpresa)) +;
" AND numfac = " + LTRIM(STR(oApl:oFac:NUMFAC)) +;
" AND tipo = '" + oApl:Tipo +;
"' AND anomes >= '" + oApl:cPer + "'"
MSQuery( oApl:oMySql:hConnect,cFactu )
EndIf
oApl:nSaldo += nPago
nPago := 0
Else
oApl:nSaldo := nAbono
EndIf
EndIf
*/
EndIf
::Cambios( lCambio,nAbono,nPago )
/*
If lCambio .AND. oApl:Tipo $ oApl:cTF
nAbono := oApl:nSaldo - nPago
oApl:oFac:INDICADOR:= If( nAbono == 0, oApl:oFac:INDICADOR, "P" )
oApl:oFac:FECHACAN := If( nAbono == 0, oApl:oFac:FECHOY, CTOD("") )
oApl:oFac:FECHAENT := If( oApl:oFac:INDICADOR == "A", oApl:dFec, oApl:oFac:FECHAENT )
GrabaSal( oApl:oFac:NUMFAC,1,nPago )
EndIf
*/
oApl:oFac:Update( .f.,1 )
FOR nR := 1 TO LEN( ::aV )
If !EMPTY( ::aV[nR,01] ) .AND. LEFT( ::aV[nR,10],1 ) == " "
nAbono := 0
::aV[nR,1] := UPPER( LTRIM(::aV[nR,1]) )
::aV[nR,6] := If( ::aV[nR,6] # 0, ::aV[nR,6], ;
ROUND( (::aV[nR,7] / (::aV[nR,7]+::aV[nR,8]))*100,2 ) )
::oVen:Seek( {"row_id",::aV[nR,11]} )
If (lCambio := (::aV[nR,11] == 0))
::oVen:EMPRESA := oApl:nEmpresa
::oVen:NUMFAC := oApl:oFac:NUMFAC
::oVen:TIPO := oApl:Tipo
Else
nAbono := ::oVen:CANTIDAD * -1
If oApl:Tipo # "Z" .AND. (::oVen:CODIGO # ::aV[nR,1] .OR. ::oVen:UNIDADMED # ::aV[nR,5])
Actualiz( ::oVen:CODIGO,nAbono,oApl:oFac:FECHOY,2,,::oVen:UNIDADMED )
nAbono := 0
EndIf
EndIf
::oVen:CODIGO := ::aV[nR,1] ; ::oVen:PPUBLI := ::aV[nR,3]
::oVen:CANTIDAD := ::aV[nR,4] ; ::oVen:UNIDADMED:= ::aV[nR,5]
::oVen:DESPOR := ::aV[nR,6] ; ::oVen:DESMON := ::aV[nR,7]
::oVen:PRECIOVEN:= ::aV[nR,8] ; ::oVen:MONTOIVA := ::aV[nR,9]
Guardar( ::oVen,lCambio,lCambio )
If oApl:Tipo # "Z"
nAbono += ::aV[nR,4]
Actualiz( ::oVen:CODIGO,nAbono,oApl:oFac:FECHOY,2,,::oVen:UNIDADMED )
If oApl:aInvme[2] # 0 .AND. oApl:aInvme[2] # ::oVen:PCOSTO
::oVen:PCOSTO := oApl:aInvme[2]
::oVen:Update( .f.,1 )
EndIf
EndIf
EndIf
NEXT nR
If oApl:lEnLinea .AND. cFactu == "SI"
CaoLiFac( {oApl:oFac:NUMFAC,::aDF[1],::cVende,"Factura"},::aV )
EndIf
oLbx:nCell := oLbx:nColPos := 1
oLbx:HiliteCell( 1 )
If oApl:oFac:FECHOY >= CTOD("01.01.2008") .AND. oApl:oFac:INDICADOR # "A" .AND.;
oApl:Tipo $ oApl:oEmp:CONTAFAC
ContaVta( ::oMvc,::oMvd,.f.,::aCta )
If oApl:oEmp:PAGOS .AND. !oApl:oFac:EFECTIVO
PagosFac( "" )
EndIf
EndIf
::Iniciar( oDlg,oLbx )
RETURN NIL
//------------------------------------//
METHOD Listado( oDlg,oLbx ) CLASS TFactura
If oApl:oFac:lOK
// If MsgNoYes( "Imprime esta Factura" )
CaoLiFac( {oApl:oFac:NUMFAC,::aDF[1],::cVende,"Factura"},::aV )
::Iniciar( oDlg,oLbx )
// EndIf
EndIf
RETURN NIL
//------------------------------------//
METHOD Abonos() CLASS TFactura
LOCAL oDlg, oLbp, oLbf, oGet := ARRAY(5), aEst, aFac, nEst
If ::aM[2] == 0 .OR. !oApl:oFac:lOK
RETURN NIL
EndIf
aEst := { "","ANULADA","PENDIENTE","CANCELADA","N.Credito","999,999,999.99",;
oApl:oFac:TOTALFAC - oApl:oFac:RETFTE - oApl:oFac:RETICA - ;
oApl:oFac:RETIVA, oApl:oFac:FECHACAN }
aFac := ArrayCol( ::aPag,1 )
nEst := AT( oApl:oFac:INDICADOR,"APCN" )
AEval( { "","","N.Credito","N.Debito","Anulada" }, {|cVal| AADD( aFac,cVal ) } )
oApl:oFam:Seek( {"empresa",oApl:nEmpresa,"numfac",::aM[2],"tipo",oApl:Tipo,;
"anomes >= ",NtChr( oApl:oFac:FECHOY,"1" )},"anomes",.f. )
oApl:cPer := NtChr( DATE(),"1" )
oApl:nSaldo := oApl:oFam:SALDO