-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.txt
More file actions
134 lines (103 loc) · 4.69 KB
/
code.txt
File metadata and controls
134 lines (103 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Export Function 2025-11-21-Aniket START
public function Export(Request $request)
{
//Defining The Exported file Column Heading For Old Export Function
// $column_heading = [
// 'DT Name',
// 'Sales Order',
// 'Order Fulfilment',
// 'AR Invoice',
// 'Sales Return',
// 'Purchase',
// 'GRPO',
// 'Purchase Return'
// ];
// Get list (key = name, value = company_id)
$excludeIds = [6, 7, 33, 34, 35];
$companyids = Company::whereIn('company_id', function ($q) {
$q->select('company_id')
->from('admin_users')
->whereIn('role', function ($r) {
$r->select('id')->from('roles')
->whereIn('name', ['Distributor', 'CFA']);
});
})
->whereNotIn('company_id', $excludeIds) // <-- exclude Sub Distributor (10%),UAPL Support Dept, UAPL Test SubD,Sub Distributor (0%),Sub Distributor (5%)
->pluck('company_id', 'name'); // "DT Name" => company_id
$rows = collect();
foreach ($companyids as $dt_name => $company_id) {
$rows->push([
'dt_name' => $dt_name, // <-- DT name
// Apply fancy date formatting everywhere
// Date Formatting
'sales_order_date' => $this->fancyDate2(
DB::table('order_booking')
->where('company_id', $company_id)
->max('document_date')
),
'order_fulfilment_date' => $this->fancyDate2(
DB::table('order_fulfilment')
->where('company_id', $company_id)
->max('document_date')
),
'ar_invoice_date' => $this->fancyDate2(
DB::table('ar_invoice')
->where('company_id', $company_id)
->max('document_date')
),
'sales_return_date' => $this->fancyDate2(
DB::table('return_invoice')
->where('company_id', $company_id)
->max('doc_date')
),
'purchase_date' => $this->fancyDate2(DB::table('purchase_order')
->where('company_id', $company_id)
->max('document_date')),
'grpo_date' => $this->fancyDate2(DB::table('goods_service_receipts')
->where('company_id', $company_id)
->max('document_date')),
'purchase_return_date' => $this->fancyDate2(DB::table('purchase_return')
->where('company_id', $company_id)
->max('doc_date')),
]);
}
// Old Export Code without Maatwebsite/Excel and Formating 21_11_2025 Aniket START
// $fileName = "Dt_Daily_tracker__export_" . date('Y-m-d_H-i-s') . ".csv";
// $headers = [
// "Content-type" => "text/csv",
// "Content-Disposition" => "attachment; filename=$fileName",
// "Pragma" => "no-cache",
// "Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
// "Expires" => "0"
// ];
// $callback = function () use ($column_heading, $rows) {
// $file = fopen('php://output', 'w');
// // CSV HEADER — ADDING SR.NO AS FIRST COLUMN
// fputcsv($file, array_merge(['Sr No.'], $column_heading));
// $sr = 1;
// foreach ($rows as $row) {
// fputcsv($file, array_merge([$sr], $row));
// $sr++;
// }
// fclose($file);
// };
// // Clear any buffered output to avoid blank rows in CSV
// if (ob_get_length()) ob_clean();
// return response()->stream($callback, 200, $headers);
// Old Export Code without Maatwebsite/Excel Without Formating 21_11_2025 Aniket END
// New Export Code with Maatwebsite/Excel and Formating 21_11_2025 Aniket START
// Add Sr No. to rows for export class
$exportRows = [];
$sr = 1;
foreach ($rows as $row) {
$exportRows[] = array_merge([$sr], $row);
$sr++;
}
if (ob_get_length()) ob_clean(); //Required To Avoid File Corruption
return Excel::download(
new DailyTrackerExport($exportRows),
'Dt_Daily_tracker_export_' . date('Y-m-d_H-i-s') . '.xlsx'
);
// New Export Code with Maatwebsite/Excel and Formating 21_11_2025 Aniket END
}
//Export Function 2025-11-21-Aniket END