-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
3555 lines (3512 loc) · 156 KB
/
index.php
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
<?php
/*////TODO
1. validation
2. add tax amount to customer table
3. load tax amount in invoice
/*/
/*
Database Schema:
404error
errorid int
time string
ip string
url string
referer string
useragent string
contacts
customerid int
contactname string
contactphone string
contactemail string
contactid int
customers
customername string
customeraddress string
customercity string
customerstate string
customerzip string
customertax decimal
customerphone string
customerdate string
customeridPrimary int
invoices
contactid int
customerid int
invoicejob string
invoicecheckno int
paymentid int
technicianid int
languageid string
invoicetaxpercentage decimal
invoicedate string
invoicepaid string
invoicenotes string
invoiceidPrimary int
items
itemdescriptionIndex string
itemprice decimal
itemtaxable string
itemidPrimary int
languages
languageidPrimary string
paid string
invoice string
to string
technician string
job string
date string
payment string
qty string
description string
unit_price string
discount string
line_total string
total_discount string
subtotal string
sales_tax string
total string
invoice_number string
customer_id string
make_all_checks_payable_to string
send_money_with_paypal string
thank_you_msg string
lineitems
invoiceid int
lineitemquantity int
itemid int
lineitemdescription string
lineitemprice decimal
lineitemtaxable string
lineitemdiscount decimal
lineitemidPrimary int
payments
paymentdescriptionIndex string
paymentidPrimary int
settings
idPrimary int
checks_payable_to string
paypal_url string
company_name string
company_slogan string
company_address string
company_phone string
company_email_address string
from_email_address string
from_name string
reply_to_email_address string
languageid string
technicians
technicianfirstname string
technicianlastname string
technicianusername string
technicianpassword string
technicianemailaddress string
technicianidPrimary int
invoiceinfo
CREATE view `invoiceinfo` AS
SELECT `inv`.`invoiceid` AS `invoiceid`,
`inv`.`invoicejob` AS `invoicejob`,
`inv`.`invoicetaxpercentage` AS `invoicetaxpercentage`,
`inv`.`invoicecheckno` AS `invoicecheckno`,
`inv`.`invoicedate` AS `invoicedate`,
`inv`.`invoicepaid` AS `invoicepaid`,
`inv`.`invoicenotes` AS `invoicenotes`,
`cus`.`customerid` AS `customerid`,
`cus`.`customername` AS `customername`,
`cus`.`customeraddress` AS `customeraddress`,
`cus`.`customercity` AS `customercity`,
`cus`.`customerstate` AS `customerstate`,
`cus`.`customerzip` AS `customerzip`,
`cus`.`customerphone` AS `customerphone`,
`cus`.`customerdate` AS `customerdate`,
`con`.`contactname` AS `contactname`,
`con`.`contactphone` AS `contactphone`,
`con`.`contactemail` AS `contactemail`,
`pay`.`paymentdescription` AS `paymentdescription`,
`tec`.`technicianfirstname` AS `technicianfirstname`,
`tec`.`technicianlastname` AS `technicianlastname`,
`inv`.`languageid` AS `languageid`
FROM `invoices` `inv`
LEFT JOIN `customers` `cus`
ON `cus`.`customerid` = `inv`.`customerid`
LEFT JOIN `payments` `pay`
ON `pay`.`paymentid` = `inv`.`paymentid`
LEFT JOIN `contacts` `con`
ON `con`.`contactid` = `inv`.`contactid`
LEFT JOIN `technicians` `tec`
ON `inv`.`technicianid` = `tec`.`technicianid`;
*/
require_once('./includes/mobile_device_detect.inc');
$ismobile = false;
$mobile = mobile_device_detect(true,false,true,true,true,true,true,false,false);
if($mobile && !isset($_GET['m']) || !$mobile && isset($_GET['m']))
{
$ismobile = true;
}
session_start();
if(isset($_REQUEST['logout']))
{
$_SESSION['loggedin'] = "no";
session_destroy();
}
$mtext = ($ismobile? "true" : "false");
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 'yes'){
$title = 'Invoices';
$script = <<<END
var mobile = {$mtext};
var dwidth = (mobile)? "600" : "auto"
var loadingQueue = 1;
var invoiceSID = -1;
var customerSID = -1;
var contactSID = -1;
var itemSID = -1;
var paymentSID = -1;
var technicianSID = -1;
var languageSID = -1;
var lineitemSID = -1;
$(document).ready(function(){
setInvoiceOptions("#page #selectinvoice", undefined, false);
setCustomerOptions("#page #selectcustomer", undefined, false);
setContactOptions(-1, "#page #selectcontact", undefined, false);
setItemOptions("#page #selectitem", undefined, false, undefined, "");
setPaymentOptions("#page #selectpayment", undefined, false);
setTechnicianOptions("#page #selecttechnician", undefined, false);
setLanguageOptions("#page #selectlanguage", undefined, false);
$("#viewpdfinvoice").click(function(){
if($("#selectinvoice").val() != '')
{
window.open("invoice.php?id=" + $("#selectinvoice").val(), "_blank");
}
else
{
message("Can't Do It!");
}
});
$("#downloadpdfinvoice").click(function(){
if($("#selectinvoice").val() != '')
{
location.href = "invoice.php?id=" + $("#selectinvoice").val() + "&download";
}
else
{
message("Can't Do It!");
}
});
$("#htmlpdfinvoice").click(function(){
if($("#selectinvoice").val() != '')
{
window.open("invoice.php?id=" + $("#selectinvoice").val() + "&html", "_blank");
}
else
{
message("Can't Do It!");
}
});
$("#emailpdfinvoice").click(function(){
if($("#selectinvoice").val() != '')
{
startLoading("Loading Email Box...");
$.post("ajax.php", {task: "get", table: "invoice", id: $("#selectinvoice").val()}, function(data){
$("<div id='emailinvoice'>"+
"<table><tbody>"+
"<tr><td><label for='contactid'>Contact</label></td><td><select name='contactid' id='contactid'><option value=''>Loading Contacts...</option></select> <button id='editcontact'>edit</button> <button id='removecontact'>X</button></td></tr>"+
"<tr><td><label for='contactemail'>Email</label></td><td><input type='email' name='contactemail' id='contactemail' /></td></tr>"+
"<tr><td><label for='message'>Message</label></td><td><textarea name='message' id='message'>"+
"Invoice is attached.\\n"+
"\\n"+
"Thanks,\\n"+
"\\n"+
"Tony Brix\\n"+
"Owner\\n"+
"UziTech.com\\n"+
"Cell: (320) 249-1820\\n"+
"TBrix13@UziTech.com"+
"</textarea></td></tr>"+
"</tbody></table>"+
"</div>")
.appendTo("body")
.dialog({
buttons: { "Send Invoice": function(){ if(sendInvoice()){ $(this).dialog("close"); }}, "Cancel": function(){ $(this).dialog("close"); }},
close: function(event, ui){ $(this).remove(); },
height: 'auto',
modal: true,
resizable: false,
title: "Send Invoice",
width: dwidth
});
$("#loading").parent().css({'z-index': parseInt($("#emailinvoice").parent().css("z-index")) + 2}).next().css({'z-index': parseInt($("#emailinvoice").parent().css("z-index")) + 1});
$("#emailinvoice button").button();
setContactOptions(data['customerid'], "#emailinvoice #contactid", ($("#selectcontact").val()? $("#selectcontact").val() : "(0)"), true, {close: function(){
if($("#emailinvoice #contactid").val() != '')
{
startLoading("Loading Contact Email...");
$.post("ajax.php", {task: "get", table: "contact", id: $("#emailinvoice #contactid").val()}, function(data){
$("#emailinvoice #contactemail").val(data['contactemail']);
endLoading("Loading Contact Email...");
}, "json");
}
}});
$("#emailinvoice #contactid").change(function(){
if($(this).val() == "newcontact")
{
$(this).val("");
newContact($("#emailinvoice #customerid").val(), {close: function(){
$("#emailinvoice #contactid option[value='newcontact']").before("<option value='"+$("#newcontact #contactid").val()+"' selected='selected'>"+$("#newcontact #contactname").val()+"</option>");
$("#emailinvoice #contactemail").val($("#newcontact #contactemail").val());
$("#page #selectcontact").append("<option value='" + $("#newcontact #contactid").val() + "'>" + $("#newcontact #contactname").val() + "</option>");
}});
}
else if($(this).val() != "")
{
startLoading("Loading Contact Email...");
$.post("ajax.php", {task: "get", table: "contact", id: $(this).val()}, function(data){
$("#emailinvoice #contactemail").val(data['contactemail']);
endLoading("Loading Contact Email...");
}, "json");
}
else
{
$("#emailinvoice #contactemail").val("");
}
});
$("#emailinvoice #editcontact").click(function(){
if(!isNaN(parseInt($("#emailinvoice #contactid").val())) && parseInt($("#emailinvoice #contactid").val()) > 0)
{
editContact($("#emailinvoice #contactid").val(), {close: function(){
$("#emailinvoice #contactid option[value='" + $("#editcontact #contactid").val() + "']").text($("#editcontact #contactname").val());
$("#emailinvoice #contactemail").val($("#editcontact #contactemail").val());
$("#page #selectcontact option[value='" + $("#editcontact #contactid").val() + "']").text($("#editcontact #contactname").val());
}});
}
return false;
});
$("#emailinvoice #removecontact").click(function(){
if(!isNaN(parseInt($("#emailinvoice #contactid").val())) && parseInt($("#emailinvoice #contactid").val()) > 0)
{
removeContact($("#emailinvoice #contactid").val(), {close: function(){
$("#page #selectcontact option[value='" + $("#emailinvoice #contactid").val() + "']").remove();
$("#emailinvoice #contactid option[value='" + $("#emailinvoice #contactid").val() + "']").remove();
$("#emailinvoice #contactemail").val("");
}});
}
return false;
});
endLoading("Loading Email Box...");
}, "json");
}
else
{
message("Can't Do It!");
}
});
$("#editsettings").click(function(){
END;
if($_SESSION['userid'] != 0)
{
$script .= <<<END
alert("You do not have permission for this!");
END;
}
else
{
$script .= <<<END
startLoading("Loading Settings...");
$.post("ajax.php", {task: "get", table: "settings"}, function(data){
$("<div id='editsettings'>"+
"<table><tbody>"+
"<tr><td><label for='checks_payable_to'>Checks Payable To</label></td><td><input type='text' name='checks_payable_to' id='checks_payable_to' value='"+data['checks_payable_to']+"' /></td></tr>"+
"<tr><td><label for='paypal_url'>PayPal URL</label></td><td><input type='text' name='paypal_url' id='paypal_url' value='"+data['paypal_url']+"' /></td></tr>"+
"<tr><td><label for='company_name'>Company Name</label></td><td><input type='text' name='company_name' id='company_name' value='"+data['company_name']+"' /></td></tr>"+
"<tr><td><label for='company_slogan'>Company Slogan</label></td><td><input type='text' name='company_slogan' id='company_slogan' value='"+data['company_slogan']+"' /></td></tr>"+
"<tr><td><label for='company_address'>Company Address</label></td><td><input type='text' name='company_address' id='company_address' value='"+data['company_address']+"' /></td></tr>"+
"<tr><td><label for='company_phone'>Company Phone</label></td><td><input type='phone' name='company_phone' id='company_phone' value='"+data['company_phone']+"' /></td></tr>"+
"<tr><td><label for='company_email_address'>Company Email Address</label></td><td><input type='email' name='company_email_address' id='company_email_address' value='"+data['company_email_address']+"' /></td></tr>"+
"<tr><td><label for='from_email_address'>From Email Address</label></td><td><input type='email' name='from_email_address' id='from_email_address' value='"+data['from_email_address']+"' /></td></tr>"+
"<tr><td><label for='from_name'>From Name</label></td><td><input type='text' name='from_name' id='from_name' value='"+data['from_name']+"' /></td></tr>"+
"<tr><td><label for='reply_to_email_address'>Reply To Email Address</label></td><td><input type='email' name='reply_to_email_address' id='reply_to_email_address' value='"+data['reply_to_email_address']+"' /></td></tr>"+
"<tr><td><label for='languageid'>Default Language</label></td><td><select name='languageid' id='languageid'><option value=''>Loading Languages...</option></select> <button id='editlanguage'>edit</button> <button id='removelanguage'>X</button></td></tr>"+
"</tbody></table>"+
"</div>")
.appendTo("body")
.dialog({
buttons: { "Update Settings": function(){ if(updateSettings()){ $(this).dialog("close"); }}, "Cancel": function(){ $(this).dialog("close"); }},
close: function(event, ui){ $(this).remove(); },
height: 'auto',
modal: true,
resizable: false,
title: "Edit Settings",
width: dwidth
});
$("#loading").parent().css({'z-index': parseInt($("#editsettings").parent().css("z-index")) + 2}).next().css({'z-index': parseInt($("#editsettings").parent().css("z-index")) + 1});
$("#editsettings button").button();
setLanguageOptions("#editsettings #languageid", data['languageid'], true);
$("#editsettings #languageid").change(function(){
if($(this).val() == "newlanguage")
{
$(this).val("");
newLanguage({close: function(){
$("#editsettings #languageid option[value='newlanguage']").before("<option value='"+$("#newlanguage #languageid").val()+"' selected='selected'>"+$("#newlanguage #languageid").val()+"</option>");
$("#page #selectlanguage").append("<option value='" + $("#newlanguage #languageid").val() + "'>" + $("#newlanguage #languageid").val() + "</option>");
}});
}
});
$("#editsettings #editlanguage").click(function(){
if($("#editsettings #languageid").val() != '' && $("#editsettings #languageid").val() != 'newlanguage')
{
editLanguage($("#editsettings #languageid").val(), {close: function(){
$("#editsettings #languageid option[value='" + $("#editlanguage #languageid").val() + "']").text($("#editlanguage #languageid").val());
$("#page #selectlanguage option[value='" + $("#editlanguage #languageid").val() + "']").text($("#editlanguage #languageid").val());
}});
}
else
{
message("No Language Selected!");
}
return false;
});
$("#editsettings #removelanguage").click(function(){
if($("#editsettings #languageid").val() != '' && $("#editsettings #languageid").val() != 'newlanguage')
{
removeLanguage($("#editsettings #languageid").val(), {close: function(){
$("#page #selectlanguage option[value='" + $("#editsettings #languageid").val() + "']").remove();
$("#editsettings #languageid option[value='" + $("#editsettings #languageid").val() + "']").remove();
}});
}
else
{
message("No Language Selected!");
}
return false;
});
endLoading("Loading Settings...");
}, "json");
END;
}
$script .= <<<END
});
$("#page #searchinvoices").keyup(function(e){
setInvoiceOptions("#page #selectinvoice", undefined, false, undefined, $("#page #searchinvoices").val(), false);
});
$("#page #searchcustomers").keyup(function(e){
setCustomerOptions("#page #selectcustomer", undefined, false, undefined, $("#page #searchcustomers").val(), false);
});
$("#page #searchcontacts").keyup(function(e){
setContactOptions(-1, "#page #selectcontact", undefined, false, undefined, $("#page #searchcontacts").val(), false);
});
$("#page #searchitems").keyup(function(e){
setItemOptions("#page #selectitem", undefined, false, undefined, $("#page #searchitems").val(), false);
});
$("#page #searchpayments").keyup(function(e){
setPaymentOptions("#page #selectpayment", undefined, false, undefined, $("#page #searchpayments").val(), false);
});
$("#page #searchtechnicians").keyup(function(e){
setTechnicianOptions("#page #selecttechnician", undefined, false, undefined, $("#page #searchtechnicians").val(), false);
});
$("#page #searchlanguages").keyup(function(e){
setLanguageOptions("#page #selectlanguage", undefined, false, undefined, $("#page #searchlanguages").val(), false);
});
$("#page #newinvoice").click(function(){
newInvoice({close: function(){
$("#page #selectinvoice option[value='']").after("<option value='" + $("#newinvoice #invoiceid").val() + "'>#" + $("#newinvoice #invoiceid").val() + " " + (($("#newinvoice #customerid").val() == "")? "No Customer" : $("#newinvoice #customerid option[value='" + $("#newinvoice #customerid").val() + "']").text()) + " " + $("#newinvoice #invoicedate").val() + "</option>");
if($("#page #searchinvoices").val() != "")
{
setInvoiceOptions("#page #selectinvoice", undefined, false, undefined, $("#page #searchinvoices").val(), false);
}
}});
return false;
});
$("#page #newcustomer").click(function(){
newCustomer({close: function(){
$("#page #selectcustomer").append("<option value='" + $("#newcustomer #customerid").val() + "'>" + $("#newcustomer #customername").val() + "</option>");
newContact($("#newcustomer #customerid").val(), {close: function(){
$("#page #selectcontact").append("<option value='" + $("#newcontact #contactid").val() + "'>" + $("#newcontact #contactname").val() + "</option>");
}});
}});
return false;
});
$("#page #newcontact").click(function(){
newContact({close: function(){
$("#page #selectcontact").append("<option value='" + $("#newcontact #contactid").val() + "'>" + $("#newcontact #contactname").val() + "</option>");
}});
return false;
});
$("#page #newitem").click(function(){
newItem({close: function(){
$("#page #selectitem").append("<option value='" + $("#newitem #itemid").val() + "'>" + $("#newitem #itemdescription").val() + "</option>");
}});
return false;
});
$("#page #newpayment").click(function(){
newPayment({close: function(){
$("#page #selectpayment").append("<option value='" + $("#newpayment #paymentid").val() + "'>" + $("#newpayment #paymentdescription").val() + "</option>");
}});
return false;
});
$("#page #newtechnician").click(function(){
newTechnician({close: function(){
$("#page #selecttechnician").append("<option value='" + $("#newtechnician #technicianid").val() + "'>" + $("#newtechnician #technicianfirstname").val() + " " + $("#newtechnician #technicianlastname").val() + "</option>");
}});
return false;
});
$("#page #newlanguage").click(function(){
newLanguage({close: function(){
$("#page #selectlanguage").append("<option value='" + $("#newlanguage #languageid").val() + "'>" + $("#newlanguage #languageid").val() + "</option>");
}});
return false;
});
$("#page #editinvoice").click(function(){
if($("#page #selectinvoice").val() != "")
{
editInvoice($("#page #selectinvoice").val(), {close: function(){
$("#page #selectinvoice option[value='" + $("#editinvoice #invoiceid").val() + "']").text("#" + $("#editinvoice #invoiceid").val() + " " + $("#editinvoice #customerid option[value='" + $("#editinvoice #customerid").val() + "']").text() + " " + $("#editinvoice #invoicedate").val());
if($("#page #searchinvoices").val() != "")
{
setInvoiceOptions("#page #selectinvoice", undefined, false, undefined, $("#page #searchinvoices").val(), false);
}
}});
}
else
{
message("No Invoice Selected!");
}
return false;
});
$("#page #editcustomer").click(function(){
if($("#page #selectcustomer").val() != "")
{
editCustomer($("#page #selectcustomer").val(), {close: function(){
$("#page #selectcustomer option[value='" + $("#editcustomer #customerid").val() + "']").text($("#editcustomer #customername").val());
}});
}
else
{
message("No Customer Selected!");
}
return false;
});
$("#page #editcontact").click(function(){
if($("#page #selectcontact").val() != "")
{
editContact($("#page #selectcontact").val(), {close: function(){
$("#page #selectcontact option[value='" + $("#editcontact #contactid").val() + "']").text($("#editcontact #contactname").val());
}});
}
else
{
message("No Contact Selected!");
}
return false;
});
$("#page #edititem").click(function(){
if($("#page #selectitem").val() != "" && $("#page #selectitem").val() != "0")
{
editItem($("#page #selectitem").val(), {close: function(){
$("#page #selectitem option[value='" + $("#edititem #itemid").val() + "']").text($("#edititem #itemdescription").val());
}});
}
else
{
message("No Item Selected!");
}
return false;
});
$("#page #editpayment").click(function(){
if($("#page #selectpayment").val() != "")
{
editPayment($("#page #selectpayment").val(), {close: function(){
$("#page #selectpayment option[value='" + $("#editpayment #paymentid").val() + "']").text($("#editpayment #paymentdescription").val());
}});
}
else
{
message("No Payment Selected!");
}
return false;
});
$("#page #edittechnician").click(function(){
if($("#page #selecttechnician").val() != "")
{
editTechnician($("#page #selecttechnician").val(), {close: function(){
$("#page #selecttechnician option[value='" + $("#edittechnician #technicianid").val() + "']").text($("#edittechnician #technicianfirstname").val() + " " + $("#edittechnician #technicianlastname").val());
}});
}
else
{
message("No Technician Selected!");
}
return false;
});
$("#page #editlanguage").click(function(){
if($("#page #selectlanguage").val() != "")
{
editLanguage($("#page #selectlanguage").val(), {close: function(){
$("#page #selectlanguage option[value='" + $("#editlanguage #languageid").val() + "']").text($("#editlanguage #languageid").val());
}});
}
else
{
message("No Language Selected!");
}
return false;
});
$("#page #deleteinvoice").click(function(){
if($("#page #selectinvoice").val() != "")
{
removeInvoice($("#page #selectinvoice").val(), {close: function(){
$("#page #selectinvoice option[value='" + $("#page #selectinvoice").val() + "']").remove();
}});
}
else
{
message("No Invoice Selected!");
}
return false;
});
$("#page #deletecustomer").click(function(){
if($("#page #selectcustomer").val() != "")
{
removeCustomer($("#page #selectcustomer").val(), {close: function(){
$("#page #selectcustomer option[value='" + $("#page #selectcustomer").val() + "']").remove();
}});
}
else
{
message("No Customer Selected!");
}
return false;
});
$("#page #deletecontact").click(function(){
if($("#page #selectcontact").val() != "")
{
removeContact($("#page #selectcontact").val(), {close: function(){
$("#page #selectcontact option[value='" + $("#page #selectcontact").val() + "']").remove();
}});
}
else
{
message("No Contact Selected!");
}
return false;
});
$("#page #deleteitem").click(function(){
if($("#page #selectitem").val() != "" && $("#page #selectitem").val() != "0")
{
removeItem($("#page #selectitem").val(), {close: function(){
$("#page #selectitem option[value='" + $("#page #selectitem").val() + "']").remove();
}});
}
else
{
message("No Item Selected!");
}
return false;
});
$("#page #deletepayment").click(function(){
if($("#page #selectpayment").val() != "")
{
removePayment($("#page #selectpayment").val(), {close: function(){
$("#page #selectpayment option[value='" + $("#page #selectpayment").val() + "']").remove();
}});
}
else
{
message("No Payment Selected!");
}
return false;
});
$("#page #deletetechnician").click(function(){
if($("#page #selecttechnician").val() != "")
{
removeTechnician($("#page #selecttechnician").val(), {close: function(){
$("#page #selecttechnician option[value='" + $("#page #selecttechnician").val() + "']").remove();
}});
}
else
{
message("No Technician Selected!");
}
return false;
});
$("#page #deletelanguage").click(function(){
if($("#page #selectlanguage").val() != "")
{
removeLanguage($("#page #selectlanguage").val(), {close: function(){
$("#page #selectlanguage option[value='" + $("#page #selectlanguage").val() + "']").remove();
}});
}
else
{
message("No Language Selected!");
}
return false;
});
$("button").button();
endLoading("Loading DOM...");
message("Done Loading!");
}); ///////////////////////////////////end jquery document ready/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
function sendInvoice()
{
rt = true;
startLoading("Sending Invoice...");
$.ajax({async: false, type: "POST", url: "invoice.php", data: {id: $("#selectinvoice").val(), email: $("#emailinvoice #contactemail").val(), message: $("#emailinvoice #message").val()}, success: function(data){
if(data != "1")
{
alert(data);
rt = false;
}
endLoading("Sending Invoice...");
}});
return rt;
}
/*function invoice(event, edit)
{
var d = new Date();
var dString = d.getFullYear();
dString += "-";
dString += (d.getMonth() + 1 < 10)? "0" + (d.getMonth() + 1) : (d.getMonth() + 1);
dString += "-";
dString += (d.getDate() < 10)? "0" + d.getDate() : d.getDate();
$("<div id='invoice'>"+
"<form action='return false;' method='#'>"+
"<table><tbody>"+
"<tr><td><label for='invoiceid'>Invoice ID</label></td><td><input type='text' name='invoiceid' id='invoiceid' readonly='readonly'/></td></tr>"+
"<tr><td><label for='invoicejob'>Job</label></td><td><input type='text' name='invoicejob' id='invoicejob' /></td></tr>"+
"<tr><td><label for='invoicetaxpercentage'>Tax Percentage</label></td><td><input type='number' name='invoicetaxpercentage' id='invoicetaxpercentage' />%</td></tr>"+
"<tr><td><label for='invoicedate'>Invoice Date</label></td><td><input type='date' name='invoicedate' id='invoicedate' placeholder='yyyy-mm-dd' value='"+dString+"' /></td></tr>"+
"<tr><td><label for='customerid'>Customer</label></td><td><select name='customerid' id='customerid'><option value=''>Loading Customers...</option></select> <button id='editcustomer'>edit</button> <button id='removecustomer'>X</button></td></tr>"+
"<tr><td><label for='contactid'>Contact</label></td><td><select name='contactid' id='contactid'><option value=''>Select a Customer</option></select> <button id='editcontact'>edit</button> <button id='removecontact'>X</button></td></tr>"+
"<tr><td><label for='paymentid'>Payment</label></td><td><select name='paymentid' id='paymentid'><option value=''>Loading Payments...</option></select> <button id='editpayment'>edit</button> <button id='removepayment'>X</button></td></tr>"+
"<tr><td><label for='invoicecheckno'>Check No</label></td><td><input type='number' name='invoicecheckno' id='invoicecheckno' /></td></tr>"+
"<tr><td><label for='technicianid'>Technician</label></td><td><select name='technicianid' id='technicianid'><option value=''>Loading Technician...</option></select> <button id='edittechnician'>edit</button> <button id='removetechnician'>X</button></td></tr>"+
"<tr><td><label for='languageid'>Language</label></td><td><select name='languageid' id='languageid'><option value=''>Loading Language...</option></select> <button id='editlanguage'>edit</button> <button id='removelanguage'>X</button></td></tr>"+
"<tr><td><label for='invoicepaid'>Paid</label></td><td><select name='invoicepaid' id='invoicepaid'><option value='N' selected='selected'>N</option><option value='Y'>Y</option></select></td></tr>"+
"<tr><td><label for='lineitems'>Line Items</label></td><td><select name='lineitems' id='lineitems'><option value=''>Line Items</option><option value='newlineitem'>New Line Item</option></select> <button id='editlineitem'>edit</button> <button id='removelineitem'>X</button></td></tr>"+
"<tr><td><label for='invoicenotes'>Notes</label></td><td><textarea name='invoicenotes' id='invoicenotes'></textarea></td></tr>"+
"</tbody></table>"+
"</form>"+
"</div>")
.appendTo("body")
.dialog({
buttons: { ((edit)?"Update Invoice" : "Add Invoice"): function(){ if(edit){if(updateInvoice(event)){ $(this).dialog("close"); }}else{{if(addInvoice(event)){ $(this).dialog("close"); }}}, "Cancel": function(){ if(!edit){removeInvoiceLineItems($("#newinvoice #invoiceid").val());} $(this).dialog("close"); }},
close: function(event, ui){ $(this).remove(); },
height: 'auto',
modal: true,
resizable: false,
title: ((edit)?"Edit Invoice" : "New Invoice"),
width: dwidth
});
startLoading("Loading Invoice...");
$("#invoice button").button();
if(edit)
{
}
else
{
$.post("ajax.php", {task: "getnextautoid", table: "invoices"}, function(data){
if(!isNaN(parseInt(data)))
{
$("#invoice #invoiceid").val(data);
}
else
{
alert(data);
}
endLoading("Loading Invoice...");
}, "text");
}
setCustomerOptions("#newinvoice #customerid");
setPaymentOptions("#newinvoice #paymentid");
setTechnicianOptions("#newinvoice #technicianid"
END;
if($_SESSION['userid'] > 0)
{
$script .= ", {$_SESSION['userid']}";
}
$script .= <<<END
);
startLoading("Getting Default Language...");
$.post("ajax.php", {task: "get", table: "settings"}, function(data){
setLanguageOptions("#newinvoice #languageid", data['languageid']);
endLoading("Getting Default Language...");
}, "json");
$("#newinvoice #customerid").change(function(){
if($(this).val() == "newcustomer")
{
$(this).val("");
newCustomer({close: function(){
$("#newinvoice #customerid option[value='newcustomer']").before("<option value='"+$("#newcustomer #customerid").val()+"' selected='selected'>"+$("#newcustomer #customername").val()+"</option>");
$("#page #selectcustomer").append("<option value='" + $("#newcustomer #customerid").val() + "'>" + $("#newcustomer #customername").val() + "</option>");
newContact($("#newcustomer #customerid").val(), {close: function(){
$("#newinvoice #contactid").append("<option value='"+$("#newcontact #contactid").val()+"' selected='selected'>"+$("#newcontact #contactname").val()+"</option>");
$("#page #selectcontact").append("<option value='" + $("#newcontact #contactid").val() + "'>" + $("#newcontact #contactname").val() + "</option>");
}});
}});
}
else if($(this).val() == "")
{
$("#newinvoice #contactid").html("<option value='' selected='selected'>Select a Customer</option>");
}
else
{
setContactOptions($(this).val(), "#newinvoice #contactid");
}
});
$("#newinvoice #contactid").change(function(){
if($(this).val() == "newcontact")
{
$(this).val("");
newContact($("#newinvoice #customerid").val(), {close: function(){
$("#newinvoice #contactid option[value='newcontact']").before("<option value='"+$("#newcontact #contactid").val()+"' selected='selected'>"+$("#newcontact #contactname").val()+"</option>");
$("#page #selectcontact").append("<option value='" + $("#newcontact #contactid").val() + "'>" + $("#newcontact #contactname").val() + "</option>");
}});
}
});
$("#newinvoice #paymentid").change(function(){
if($(this).val() == "newpayment")
{
$(this).val("");
newPayment({close: function(){
$("#newinvoice #paymentid option[value='newpayment']").before("<option value='"+$("#newpayment #paymentid").val()+"' selected='selected'>"+$("#newpayment #paymentdescription").val()+"</option>");
$("#page #selectpayment").append("<option value='" + $("#newpayment #paymentid").val() + "'>" + $("#newpayment #paymentdescription").val() + "</option>");
}});
}
});
$("#newinvoice #technicianid").change(function(){
if($(this).val() == "newtechnician")
{
$(this).val("");
newTechnician({close: function(){
$("#newinvoice #technicianid option[value='newtechnician']").before("<option value='"+$("#newtechnician #technicianid").val()+"' selected='selected'>"+$("#newtechnician #technicianfirstname").val()+" "+$("#newtechnician #technicianlastname").val()+"</option>");
$("#page #selecttechnician").append("<option value='" + $("#newtechnician #technicianid").val() + "'>" + $("#newtechnician #technicianfirstname").val() + " " + $("#newtechnician #technicianlastname").val() + "</option>");
}});
}
});
$("#newinvoice #languageid").change(function(){
if($(this).val() == "newlanguage")
{
$(this).val("");
newLanguage({close: function(){
$("#newinvoice #languageid option[value='newlanguage']").before("<option value='"+$("#newlanguage #languageid").val()+"' selected='selected'>"+$("#newlanguage #languageid").val()+"</option>");
$("#page #selectlanguage").append("<option value='" + $("#newlanguage #languageid").val() + "'>" + $("#newlanguage #languageid").val() + "</option>");
}});
}
});
$("#newinvoice #lineitems").change(function(){
if($(this).val() == "newlineitem")
{
$(this).val("");
newLineItem($("#newinvoice #invoiceid").val(), {close: function(){
$("#newinvoice #lineitems option[value='newlineitem']").before("<option value='"+$("#newlineitem #lineitemid").val()+"' selected='selected'>"+$("#newlineitem #lineitemquantity").val()+" "+$("#newlineitem #lineitemdescription").val()+"</option>");
}});
}
});
$("#newinvoice #editcustomer").click(function(){
if(!isNaN(parseInt($("#newinvoice #customerid").val())) && parseInt($("#newinvoice #customerid").val()) > 0)
{
editCustomer($("#newinvoice #customerid").val(), {close: function(){
$("#newinvoice #customerid option[value='" + $("#editcustomer #customerid").val() + "']").text($("#editcustomer #customername").val());
$("#page #selectcustomer option[value='" + $("#editcustomer #customerid").val() + "']").text($("#editcustomer #customername").val());
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #editcontact").click(function(){
if(!isNaN(parseInt($("#newinvoice #contactid").val())) && parseInt($("#newinvoice #contactid").val()) > 0)
{
editContact($("#newinvoice #contactid").val(), {close: function(){
$("#newinvoice #contactid option[value='" + $("#editcontact #contactid").val() + "']").text($("#editcontact #contactname").val());
$("#page #selectcontact option[value='" + $("#editcontact #contactid").val() + "']").text($("#editcontact #contactname").val());
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #editpayment").click(function(){
if(!isNaN(parseInt($("#newinvoice #paymentid").val())) && parseInt($("#newinvoice #paymentid").val()) > 0)
{
editPayment($("#newinvoice #paymentid").val(), {close: function(){
$("#newinvoice #paymentid option[value='" + $("#editpayment #paymentid").val() + "']").text($("#editpayment #paymentdescription").val());
$("#page #selectpayment option[value='" + $("#editpayment #paymentid").val() + "']").text($("#editpayment #paymentdescription").val());
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #edittechnician").click(function(){
if(!isNaN(parseInt($("#newinvoice #technicianid").val())) && parseInt($("#newinvoice #technicianid").val()) > 0)
{
editTechnician($("#newinvoice #technicianid").val(), {close: function(){
$("#newinvoice #technicianid option[value='" + $("#edittechnician #technicianid").val() + "']").text($("#edittechnician #technicianfirstname").val() + " " + $("#edittechnician #technicianlastname").val());
$("#page #selecttechnician option[value='" + $("#edittechnician #technicianid").val() + "']").text($("#edittechnician #technicianfirstname").val() + " " + $("#edittechnician #technicianlastname").val());
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #editlanguage").click(function(){
if($("#newinvoice #languageid").val() != '' && $("#newinvoice #languageid").val() != 'newlanguage')
{
editLanguage($("#newinvoice #languageid").val(), {close: function(){
$("#newinvoice #languageid option[value='" + $("#editlanguage #languageid").val() + "']").text($("#editlanguage #languageid").val());
$("#page #selectlanguage option[value='" + $("#editlanguage #languageid").val() + "']").text($("#editlanguage #languageid").val());
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #editlineitem").click(function(){
if(!isNaN(parseInt($("#newinvoice #lineitems").val())) && parseInt($("#newinvoice #lineitems").val()) > 0)
{
editLineItem($("#newinvoice #lineitems").val(), {close: function(){
$("#newinvoice #lineitems option[value='" + $("#editlineitem #lineitemid").val() + "']").text($("#editlineitem #lineitemquantity").val() + " " + $("#editlineitem #lineitemdescription").val());
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #removecustomer").click(function(){
if(!isNaN(parseInt($("#newinvoice #customerid").val())) && parseInt($("#newinvoice #customerid").val()) > 0)
{
removeCustomer($("#newinvoice #customerid").val(), {close: function(){
$("#page #selectcustomer option[value='" + $("#newinvoice #customerid").val() + "']").remove();
$("#newinvoice #customerid option[value='" + $("#newinvoice #customerid").val() + "']").remove();
$("#newinvoice #contactid").html("<option value=''>Select a Customer</option>");
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #removecontact").click(function(){
if(!isNaN(parseInt($("#newinvoice #contactid").val())) && parseInt($("#newinvoice #contactid").val()) > 0)
{
removeContact($("#newinvoice #contactid").val(), {close: function(){
$("#page #selectcontact option[value='" + $("#newinvoice #contactid").val() + "']").remove();
$("#newinvoice #contactid option[value='" + $("#newinvoice #contactid").val() + "']").remove();
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #removepayment").click(function(){
if(!isNaN(parseInt($("#newinvoice #paymentid").val())) && parseInt($("#newinvoice #paymentid").val()) > 0)
{
removePayment($("#newinvoice #paymentid").val(), {close: function(){
$("#page #selectpayment option[value='" + $("#newinvoice #paymentid").val() + "']").remove();
$("#newinvoice #paymentid option[value='" + $("#newinvoice #paymentid").val() + "']").remove();
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #removetechnician").click(function(){
if(!isNaN(parseInt($("#newinvoice #technicianid").val())) && parseInt($("#newinvoice #technicianid").val()) > 0)
{
removeTechnician($("#newinvoice #technicianid").val(), {close: function(){
$("#page #selecttechnician option[value='" + $("#newinvoice #technicianid").val() + "']").remove();
$("#newinvoice #technicianid option[value='" + $("#newinvoice #technicianid").val() + "']").remove();
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #removelanguage").click(function(){
if($("#newinvoice #languageid").val() != '' && $("#newinvoice #languageid").val() != 'newlanguage')
{
removeLanguage($("#newinvoice #languageid").val(), {close: function(){
$("#page #selectlanguage option[value='" + $("#newinvoice #languageid").val() + "']").remove();
$("#newinvoice #languageid option[value='" + $("#newinvoice #languageid").val() + "']").remove();
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #removelineitem").click(function(){
if(!isNaN(parseInt($("#newinvoice #lineitems").val())) && parseInt($("#newinvoice #lineitems").val()) > 0)
{
removeLineItem($("#newinvoice #lineitems").val(), {close: function(){
$("#newinvoice #lineitems option[value='" + $("#newinvoice #lineitems").val() + "']").remove();
}});
}
else
{
message("Can't Do It!");
}
return false;
});
$("#newinvoice #invoicedate").datepicker({ showOn: 'both', dateFormat: 'yy-mm-dd' });
}*/
function newInvoice(event)
{
var d = new Date();
var dString = d.getFullYear();
dString += "-";
dString += (d.getMonth() + 1 < 10)? "0" + (d.getMonth() + 1) : (d.getMonth() + 1);
dString += "-";
dString += (d.getDate() < 10)? "0" + d.getDate() : d.getDate();
$("<div id='newinvoice'>"+
"<form action='return false;' method='#'>"+
"<table><tbody>"+
"<tr><td><label for='invoiceid'>Invoice ID</label></td><td><input type='text' name='invoiceid' id='invoiceid' readonly='readonly' value='...'/></td></tr>"+