forked from jmueller17/Aixada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_sales.php
573 lines (430 loc) · 18.3 KB
/
report_sales.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
<?php include "php/inc/header.inc.php" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$language;?>" lang="<?=$language;?>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $Text['global_title'] . " - " . $Text['head_ti_sales'] . " - " . $Text['nav_report_shop_pv'] ;?></title>
<link rel="stylesheet" type="text/css" media="screen" href="css/aixada_main.css" />
<link rel="stylesheet" type="text/css" media="print" href="css/print.css" />
<link rel="stylesheet" type="text/css" media="screen" href="js/fgmenu/fg.menu.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-themes/<?=$default_theme;?>/jqueryui.css"/>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jqueryui/jqueryui.js"></script>
<?php echo aixada_js_src(); ?>
<script type="text/javascript" src="js/tablesorter/jquery.tablesorter.js" ></script>
<script type="text/javascript" src="js/jqueryui/i18n/jquery.ui.datepicker-<?=$language;?>.js" ></script>
<script type="text/javascript">
$(function(){
$.ajaxSetup({ cache: false });
//var gUniqueProviders = [];
//current provider
var gProviderId = 0;
var gSelProvider = null;
//if product sales list breaks down purchase by dates or not
var gGroupBy = ""; // = "shop_date" shows each item x individual shop date. "" sums over all dates in range
var gSection = "overview";
//filter for orderable / stock product type in product listing
var gShowStock = 1;
var gShowOrderable = 1;
//loading animatio
$('.loadSpinner').attr('src', "img/ajax-loader-<?=$default_theme;?>.gif").hide();
$("#datepicker_from").datepicker({
dateFormat : 'D, d M, yy',
onSelect : function (dateText, instance){
$('#setFromDate').text(dateText);
(gSection == 'overview')? reloadProviders():reloadProducts();
}
});
$("#datepicker_to").datepicker({
dateFormat : 'D, d M, yy',
onSelect : function (dateText, instance){
$('#setToDate').text(dateText);
(gSection == 'overview')? reloadProviders():reloadProducts();
}
});
//default, show sales for today
$.getAixadaDates('getToday', function (date){
$("#datepicker_to, #datepicker_from").datepicker('setDate', $.datepicker.parseDate('yy-mm-dd', date[0]));
});
/********************************************************
* PURCHASE PROVIER LISTING
********************************************************/
//the table sorter plugin
//$("#tbl_Providers").tablesorter();
$("#tbl_Providers").bind('sortEnd', function(){
$('tr',this).removeClass('rowHighlight')
$('tr:even',this).addClass('rowHighlight');
});
//load purchase listing
$('#tbl_Providers tbody').xml2html('init',{
url : 'php/ctrl/Shop.php',
params : 'oper=getTotalSalesByProviders&filter=exact&provider_id='+gProviderId+'&from_date='+$.getSelectedDate('#datepicker_from')+'&to_date='+$.getSelectedDate('#datepicker_to'),
loadOnInit : true,
beforeLoad : function(){
$('.loadSpinner').show();
},
rowComplete : function(rowIndex, row){
//update rev tax and iva amounts included for the given period
var revTaxQt = $('.sumRevQt', row).text() - $('.sumTotalNetto', row).text();
$('.sumRevQt', row).text(revTaxQt.toFixed(2)+"<?=$Text['currency_sign'];?>");
var ivaTaxQt = $('.sumIvaQt', row).text() - $('.sumTotalNetto', row).text();
$('.sumIvaQt', row).text(ivaTaxQt.toFixed(2)+"<?=$Text['currency_sign'];?>");
$('.sumTotalNetto', row).append("<?=$Text['currency_sign'];?>");
$('.sumTotalBrutto', row).append("<?=$Text['currency_sign'];?>");
},
complete : function(rowCount){
$('tr:even', this).addClass('rowHighlight');
//$("#tbl_Providers").trigger("update");
filterProviderList();
$('.loadSpinner').hide();
if (rowCount == 0){
$.showMsg({
msg:"<?=$Text['msg_err_order_filter'];?>",
autoclose:2000,
type: 'warning'});
}
}
});
$('#tbl_Providers tbody tr')
.live('mouseover', function(){
$(this).removeClass('highlight').addClass('ui-state-hover');
var pvid = $(this).attr('providerId');
$('#sumCell_'+pvid).addClass('ui-state-hover');
})
.live('mouseout',function(){
$(this).removeClass('ui-state-hover');
var pvid = $(this).attr('providerId');
$('#sumCell_'+pvid).removeClass('ui-state-hover');
})
.live('click',function(e){
if (gSelProvider != null) gSelProvider.removeClass('ui-state-highlight');
gSelProvider = $(this);
gProviderId = $(this).attr('providerId');
$('.setProviderName').text($(this).attr('providerName'));
$(this).addClass('ui-state-highlight');
reloadProducts();
});
$("#tblViewOptions")
.button({
icons: {
secondary: "ui-icon-triangle-1-s"
}
})
.menu({
content: $('#tblOptionsItems').html(),
showSpeed: 50,
width:280,
flyOut: true,
itemSelected: function(item){ //TODO instead of using this callback function make your own menu; if jquerui is updated, this will not work
//show hide deactivated products
var filter = $(item).attr('id');
if (filter == 'listDates'){
if (gGroupBy == ""){
$(item).children('span').addClass('ui-icon ui-icon-check');
gGroupBy = "shop_date";
} else {
$(item).children('span').removeClass('ui-icon ui-icon-check');
gGroupBy = "";
}
if (gSection == 'detail'){
reloadProducts();
} else {
reloadProviders();
}
} else if (filter == 'stock'){
if (gShowStock){
$(item).children('span').removeClass('ui-icon ui-icon-check');
gShowStock = 0;
} else if (gShowStock == 0) {
$(item).children('span').addClass('ui-icon ui-icon-check');
gShowStock = 1;
}
filterProductType();
} else if (filter == 'orderable'){
if (gShowOrderable){
$(item).children('span').removeClass('ui-icon ui-icon-check');
gShowOrderable = 0;
} else if (gShowOrderable == 0) {
$(item).children('span').addClass('ui-icon ui-icon-check');
gShowOrderable = 1;
}
filterProductType();
}
}//end item selected
});//end menu
/********************************************************
* DETAIL PURCHASE VIEW
********************************************************/
$("#tbl_products tbody").xml2html("init", {
url : 'php/ctrl/Shop.php',
params : 'oper=getDetailSalesByProvider&provider_id='+gProviderId+'&groupby='+gGroupBy+'&from_date='+$.getSelectedDate('#datepicker_from')+'&to_date='+$.getSelectedDate('#datepicker_to'),
loadOnInit: false,
rowComplete: function(rowIndex, row){
var tds = $(row).children();
//stock
if (tds.eq(4).text() == "1"){
tds.eq(4).text("<?=$Text['stock'];?>");
//orderable
} else if (tds.eq(4).text() == "2"){
tds.eq(4).text("<?=$Text['orderable'];?>");
}
if (gGroupBy == ""){
tds.eq(3).html("<span title='Select Filter > List Dates to view details'>various..</span>");
}
},
complete: function(rowCount){
filterProductType();
switchTo('detail');
}
})
$('#tbl_products tbody tr')
.live('mouseover', function(){
$(this).addClass('ui-state-hover');
})
.live('mouseout',function(){
$(this).removeClass('ui-state-hover');
});
$('#toggleProductBulkActions')
.click(function(e){
if ($(this).is(':checked')){
$('input:checkbox[name="sumProduct"]').attr('checked','checked');
} else {
$('input:checkbox[name="sumProduct"]').attr('checked',false);
}
$('input[name=sumProduct]').each(function(){
if ($(this).is(':visible')){
toggleSumProduct($(this).parents('tr'), $(this).is(':checked'));
}
})
sumTotalSales();
});
//bulk actions
$('input[name=sumProduct]')
.live('click', function(e){
toggleSumProduct($(this).parents('tr'), $(this).is(':checked'));
sumTotalSales();
})
//overview buttons
$("#btn_overview").button({
icons: {
primary: "ui-icon-circle-arrow-w"
}
})
.click(function(e){
switchTo('overview');
});
/********************************************************
* GLOBAL UTIL FUNCTIONS
********************************************************/
function switchTo(section){
gSection = section;
switch (section){
case 'detail':
$('.overviewElements').hide();
$('.salesDetailElements').fadeIn(1000);
break;
case 'overview':
$('.salesDetailElements').hide();
$('.overviewElements').fadeIn(1000);
break;
}
}
function reloadProviders(){
$('#tbl_Providers tbody').xml2html('reload',{
params : 'oper=getTotalSalesByProviders&provider_id=0&groupby='+gGroupBy+'&from_date='+$.getSelectedDate('#datepicker_from')+'&to_date='+$.getSelectedDate('#datepicker_to')
});
}
function reloadProducts(){
$("#tbl_products tbody").xml2html("reload", {
params : 'oper=getDetailSalesByProvider&provider_id='+gProviderId+'&groupby='+gGroupBy+'&from_date='+$.getSelectedDate('#datepicker_from')+'&to_date='+$.getSelectedDate('#datepicker_to')
})
}
/**
* show hide stock or fresh products in listing
*/
function filterProductType(){
if (gGroupBy == ""){
$('.shopDateCol').hide();
} else {
$('.shopDateCol').show();
}
$('#tbl_products tbody tr').each(function(){
var type = $(this).attr('orderableTypeId');
if (type == 1 && gShowStock || type == 2 && gShowOrderable){
$(this).show();
$(this).children('td:last-child').children('p:first-child').addClass('bruttoCol');
$(this).children('td:last-child').prev().children('p:first-child').addClass('nettoCol');
} else if (type == 1 && !gShowStock || type == 2 && !gShowOrderable){
$(this).hide();
$(this).children('td:last-child').children('p:first-child').removeClass('bruttoCol');
$(this).children('td:last-child').prev().children('p:first-child').removeClass('nettoCol');
}
})
sumTotalSales();
}
function filterProviderList(){
if (gGroupBy == ""){
$('.shopDateCol').hide();
} else {
$('.shopDateCol').show();
}
}
function sumTotalSales(){
var tnetto = $.sumSimpleItems('.nettoCol');
var tbrutto = $.sumSimpleItems('.bruttoCol');
$('#nettoTotal').text(tnetto +"<?=$Text['currency_sign'];?>");
$('#bruttoTotal').text(tbrutto+"<?=$Text['currency_sign'];?>");
}
/**
* switches individual product rows on/off for the overall sum calculation
* i.e calculates the sum over just stock, orderable or both depending on what is visible
*/
function toggleSumProduct(seltr, checked){
if (checked){
seltr.children('td:last-child').children('p:first-child').addClass('bruttoCol');
seltr.children('td:last-child').prev().children('p:first-child').addClass('nettoCol');
} else {
seltr.children('td:last-child').children('p:first-child').removeClass('bruttoCol');
seltr.children('td:last-child').prev().children('p:first-child').removeClass('nettoCol');
}
}
switchTo('overview');
}); //close document ready
</script>
</head>
<body>
<div id="wrap">
<div id="headwrap">
<?php include "php/inc/menu.inc.php" ?>
</div>
<!-- end of headwrap -->
<div id="stagewrap" class="<?= negative_balances_stagewrap_class() ?>">
<div id="titlewrap" class="ui-widget">
<div id="titleLeftCol50">
<button id="btn_overview" class="floatLeft salesDetailElements"><?php echo $Text['overview'];?></button>
<h1 class="overviewElements"><?php echo $Text['ti_report_shop_pv']; ?></h1>
<h1 class="salesDetailElements"><?php echo $Text['sales_total_pv']; ?> <span class="setProviderName"></span></h1>
</div>
<div id="titleRightCol50">
<button id="tblViewOptions" class="btn_right"><?=$Text['btn_filter']; ?></button>
<div id="tblOptionsItems" class="hidden">
<ul>
<li><a href="javascript:void(null)" id="listDates" ><span class="floatLeft"></span> <?php echo $Text['dates_breakdown']; ?></a></li>
<li><a href="javascript:void(null)" id="stock" ><span class="floatLeft ui-icon ui-icon-check"></span> <?php echo $Text['stock'];?></a></li>
<li><a href="javascript:void(null)" id="orderable" ><span class="floatLeft ui-icon ui-icon-check"></span> <?php echo $Text['orderable'];?></a></li>
</ul>
</div>
<table class="floatRight">
<tr>
<td><?php echo $Text['date_from']; ?>: </td>
<td><input type="text" id="datepicker_from" class="ui-corner-all"/></td>
<td> </td>
<td><?php echo $Text['date_to']; ?>: </td>
<td><input type="text" id="datepicker_to" class="ui-corner-all"/></td>
</tr>
</table>
</div>
</div>
<!--
PROVIDER LISTING
-->
<div id="purchase_list" class="ui-widget overviewElements">
<div class="ui-widget-content ui-corner-all">
<h3 class="ui-widget-header ui-corner-all"> <span style="float:right; margin-top:-4px;"><img class="loadSpinner" src="img/ajax-loader.gif"/></span></h3>
<table id="tbl_Providers" class="tblListingDefault">
<thead>
<tr>
<th><?php echo $Text['id']; ?></th>
<th class="textAlignCenter"><?php echo $Text['provider']; ?></th>
<th class="shopDateCol textAlignCenter"><?php echo $Text['purchase_date']; ?></th>
<th><p class="textAlignRight"><?php echo $Text['total_netto']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['revtax_abbrev']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['iva']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['total_brutto']; ?></p></th>
</tr>
</thead>
<tbody>
<tr providerId="{provider_id}" providerName="{provider_name}">
<td>{provider_id}</td>
<td class="clickable">{provider_name}</td>
<td class="shopDateCol">{date_for_shop}</td>
<td><p class="sumTotalNetto textAlignRight">{total_sales_netto}</p></td>
<td><p class="sumRevQt textAlignRight">{total_sales_rev}</p></td>
<td><p class="sumIvaQt textAlignRight">{total_sales_iva}</p></td>
<td><p class="sumTotalBrutto textAlignRight">{total_sales_brutto}</p></td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
</div>
</div>
<!--
DETAIL PRODUCT SALES LISTING FOR GIVEN PROVIDER
-->
<div id="purchase_detail" class="ui-widget salesDetailElements">
<div class="ui-widget-content ui-corner-all">
<h3 class="ui-widget-header ui-corner-all"> <span style="float:right; margin-top:-4px;"><img class="loadSpinner" src="img/ajax-loader.gif"/></span></h3>
<table id="tbl_products" class="tblListingDefault">
<thead>
<th> <input type="checkbox" id="toggleProductBulkActions" name="toggleProductBulk" checked="checked" title="Toggle sum items Σ"/></th>
<th><p class="textAlignCenter"><?php echo $Text['id'];?></p></th>
<th><p class="floatLeft"><?php echo $Text['name_item'];?></p></th>
<th class="shopDateCol textAlignCenter"><?php echo $Text['purchase_date']; ?></th>
<th><p class="floatLeft"><?php echo $Text['orderable_type']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['price_net']; ?></p></th>
<th><p class="textAlignCenter"><?php echo $Text['revtax_abbrev']; ?></p></th>
<th><p class="textAlignCenter"><?php echo $Text['iva']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['price_brutto']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['total_qty']; ?></p></th>
<th><p class="textAlignLeft"><?php echo $Text['unit'];?></p></th>
<th><p class="textAlignRight"><?php echo $Text['total_netto']; ?></p></th>
<th><p class="textAlignRight"><?php echo $Text['total_brutto']; ?></p></th>
</thead>
<tbody>
<tr orderableTypeId="{orderable_type_id}">
<td><input type="checkbox" name="sumProduct" checked="checked" title="Include / exclude in Σ"/></td>
<td><p class="textAlignCenter">{product_id}</p></td>
<td>{product_name}</td>
<td class="shopDateCol">{date_for_shop}</td>
<td><p class="textAlignCenter">{orderable_type_id}</p></td>
<td><p class="textAlignRight">{unit_price_stamp_netto}</p> </td>
<td><p class="textAlignCenter">{rev_tax_percent}%</p></td>
<td><p class="textAlignCenter">{iva_percent}%</p></td>
<td><p class="textAlignRight">{unit_price_stamp}</p> </td>
<td><p class="textAlignRight">{total_sales_quantity} </p></td>
<td><p class="textAlignCenter">{shop_unit}</p></td>
<td><p class="textAlignRight nettoCol">{total_sales_netto}</p></td>
<td><p class="textAlignRight bruttoCol">{total_sales_brutto}</p></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td></td>
<td class="shopDateCol"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="boldStuff"><?php echo $Text['total']?>: <span id="nettoTotal"></span></td>
<td class="boldStuff"><?php echo $Text['total']?>: <span id="bruttoTotal"></span></td></td>
</tr>
</tfoot>
</table>
</div>
</div>
<p> </p>
<p> </p>
<p> </p>
</div>
<!-- end of stage wrap -->
</div>
<!-- end of wrap -->
<!-- / END -->
</body>
</html>